Semantic Grep - Word2Vec आधारित खोज टूल
(github.com/arunsupe)- sgrep एक कमांड-लाइन टूल है जो word embeddings का उपयोग करके टेक्स्ट इनपुट पर semantic search करता है
- यह साधारण string matching से आगे बढ़कर query के लिए semantic रूप से समान matches खोजता है
- इसे grep जैसे अनुभव देने के लिए डिज़ाइन किया गया है
- सुविधाएँ
- Word2Vec embeddings का उपयोग करके semantic search
- similarity threshold सेट करने की सुविधा
- match होने वाली line के पहले और बाद का context दिखाना
- matching words और line numbers के लिए color-coded output
- files या standard input से पढ़ने का समर्थन
- JSON files और command-line arguments के माध्यम से configuration संभव
- उपयोग उदाहरण
- Hemingway की "The Old Man and the Sea" में "death" के समान शब्दों को context और line numbers के साथ खोजने के लिए:
curl -s 'https://gutenberg.ca/ebooks/hemingwaye-oldmanandthesea/…' \ | sgrep -C 2 -n -threshold 0.55 death - यह कमांड निम्न काम करता है:
- Project Gutenberg Canada से "The Old Man and the Sea" का टेक्स्ट लाता है
- टेक्स्ट को sgrep में pipe करता है
- "death" से semantic रूप से मिलते-जुलते शब्द खोजता है
- similarity threshold को 0.55 पर सेट करता है (
-threshold 0.55) - हर match के पहले और बाद की 2 lines का context दिखाता है (
-C 2) - line numbers दिखाता है (
-n)
- output में similarity score, highlighted words, context, और line numbers दिखाई देते हैं
- Hemingway की "The Old Man and the Sea" में "death" के समान शब्दों को context और line numbers के साथ खोजने के लिए:
- Word2Vec मॉडल
- sgrep को binary format में Word2Vec model चाहिए। आप Google के Word2Vec model जैसे pre-trained models का उपयोग कर सकते हैं या gensim जैसे tools से अपना model train कर सकते हैं
.binfile को लोकल में डाउनलोड करें औरconfig.jsonअपडेट करें- Google का Word2Vec: https://github.com/mmihaltz/word2vec-GoogleNews-vectors
- slim version: GoogleNews-vectors-negative300-SLIM.bin.gz model https://github.com/eyaler/word2vec-slim/ (eyaler को धन्यवाद)
download-model.shएक सरल helper script है जो eyaler द्वारा होस्ट किया गया छोटा word2vec modelmodels/googlenews-slim/directory में सहेजता है
GN⁺ का सार
- sgrep एक ऐसा टूल है जो word embeddings का उपयोग करके टेक्स्ट में semantic रूप से समान शब्द खोजता है
- यह grep जैसा उपयोग अनुभव देता है, लेकिन साधारण string matching से आगे की क्षमता प्रदान करता है
- यह similarity तय करने के लिए Word2Vec model का उपयोग करता है और कई configuration options के साथ लचीले ढंग से इस्तेमाल किया जा सकता है
- यह text analysis और natural language processing कार्यों में उपयोगी हो सकता है, खासकर जब context-based search की आवश्यकता हो
1 टिप्पणियां
Hacker News राय
कोड पढ़ते समय कुछ छोटे सुझाव साझा किए गए
यह विचार बहुत उपयोगी लगा और सोचा कि यह पहले क्यों नहीं सूझा
semgrep नाम का एक tool और company पहले से मौजूद है
अगर यह tool descriptive phrases या compound phrases को handle कर सके, तो यह बहुत उपयोगी होगा
यह बहुत शानदार tool है
यह tool बहुत शानदार है और इसे ज़रूर आज़माना चाहूँगा
मिलते-जुलते tool के रूप में fltr का सुझाव दिया गया
बहुत शानदार है, और जिज्ञासा है कि क्या यह file names भी search कर सकता है
यह बहुत शानदार tool मिला