1 पॉइंट द्वारा GN⁺ 2024-09-16 | 1 टिप्पणियां | WhatsApp पर शेयर करें

WordLlama

WordLlama एक तेज़ और हल्का NLP टूल है, जो fuzzy deduplication, similarity और ranking जैसे काम बहुत कम inference-time dependencies के साथ संभालता है, और CPU hardware के लिए optimized है.

विषय सूची

  • Quick Start
  • यह क्या है?
  • MTEB परिणाम
  • Text Embedding
  • Training Notes
  • Roadmap
  • Token Embedding Extraction
  • Citation
  • License

Quick Start

  • इंस्टॉल:

    pip install wordllama
    
  • 256-dimensional model लोड करें:

    from wordllama import WordLlama
    wl = WordLlama.load()
    
  • दो वाक्यों के बीच similarity निकालें:

    similarity_score = wl.similarity("i went to the car", "i went to the pawn shop")
    print(similarity_score)  # 출력: 0.06641249096796882
    
  • query के लिए documents की ranking करें:

    query = "i went to the car"
    candidates = ["i went to the park", "i went to the shop", "i went to the truck", "i went to the vehicle"]
    ranked_docs = wl.rank(query, candidates)
    print(ranked_docs)
    # 출력:
    # [
    #  ('i went to the vehicle', 0.7441646856486314),
    #  ('i went to the truck', 0.2832691551894259),
    #  ('i went to the shop', 0.19732814982305436),
    #  ('i went to the park', 0.15101404519322253)
    # ]
    
  • अतिरिक्त inference methods:

    wl.deduplicate(candidates, threshold=0.8)  # fuzzy deduplication
    wl.cluster(docs, k=5, max_iterations=100, tolerance=1e-4)  # kmeans/kmeans++ initialization के साथ labeling
    wl.filter(query, candidates, threshold=0.3)  # query के आधार पर candidates फ़िल्टर करें
    wl.topk(query, candidates, k=3)  # query के आधार पर top k strings लौटाएँ
    

यह क्या है?

WordLlama एक NLP और word embedding model है जो बड़े language model (LLM) के components को reuse करके efficient और compact word representations बनाता है. यह GloVe, Word2Vec, FastText जैसे models के समान है.

  • Matryoshka Representations: ज़रूरत के अनुसार embedding dimensions कम किए जा सकते हैं
  • कम resource requirements: simple token lookup with average pooling की मदद से CPU पर तेज़ी से चल सकता है
  • Binarization: straight-through estimator से trained models को छोटे integer arrays में pack किया जा सकता है (जल्द आ रहा है)
  • Numpy-only inference: हल्का और सरल

WordLlama कई तरह के NLP tasks के लिए उपयुक्त है, और अपनी तेज़ व portable size की वजह से exploratory analysis और utility applications में उपयोगी है.

MTEB परिणाम

Metric WL64 WL128 WL256 (X) WL512 WL1024 GloVe 300d Komninos all-MiniLM-L6-v2
Clustering 30.27 32.20 33.25 33.40 33.62 27.73 26.57 42.35
Reranking 50.38 51.52 52.03 52.32 52.39 43.29 44.75 58.04
Classification 53.14 56.25 58.21 59.13 59.50 57.29 57.65 63.05
Pair Classification 75.80 77.59 78.22 78.50 78.60 70.92 72.94 82.37
STS 66.24 67.53 67.91 68.22 68.27 61.85 62.46 78.90
CQA DupStack 18.76 22.54 24.12 24.59 24.83 15.47 16.79 41.32
SummEval 30.79 29.99 30.99 29.56 29.39 28.87 30.49 30.81

Text Embedding

Pretrained embeddings लोड करके text को embed करने का तरीका:

from wordllama import WordLlama
wl = WordLlama.load(trunc_dim=64)
embeddings = wl.embed(["the quick brown fox jumps over the lazy dog", "and all that jazz"])
print(embeddings.shape)  # (2, 64)

Binary embedding model के उपयोग का उदाहरण:

wl = WordLlama.load(trunc_dim=64, binary=True)
wl.embed("I went to the car")  # 출력: array([[3029168427562626]], dtype=uint64)
wl = WordLlama.load(dim=1024, binary=True)
similarity_score = wl.similarity("i went to the car", "i went to the pawn shop")
print(similarity_score)  # 출력: 0.57421875
ranked_docs = wl.rank("i went to the car", ["van", "truck"])
wl.binary = False  # Hamming similarity की जगह cosine similarity इस्तेमाल करें
wl = WordLlama.load(config="l3_supercat", dim=1024)

Training Notes

Binary embedding model ने high dimensions में अधिक स्पष्ट सुधार दिखाया, और 512 या 1024 dimensions की सिफारिश की जाती है. L2 Supercat को एक single A100 पर batch size 512 के साथ 12 घंटे तक train किया गया.

Roadmap

  • inference features जोड़ने पर काम जारी है:
    • semantic text chunking
    • example notebooks जोड़ना
    • DSPy evaluator
    • RAG pipeline

Token Embedding Extraction

Model से token embeddings निकालने के लिए आपको user agreement स्वीकार करना होगा और Hugging Face CLI का उपयोग करके login करना होगा. उसके बाद आप यह snippet इस्तेमाल कर सकते हैं:

from wordllama.extract import extract_safetensors
extract_safetensors("llama3_70B", "path/to/saved/model-0001-of-00XX.safetensors")

Citation

अगर आप WordLlama को research या project में इस्तेमाल करते हैं, तो कृपया इसे इस प्रकार cite करें:

@software{miller2024wordllama,
  author = {Miller, D. Lee},
  title = {WordLlama: Recycled Token Embeddings from Large Language Models},
  year = {2024},
  url = {https://github.com/dleemiller/wordllama},
  version = {0.2.6}
}

License

यह प्रोजेक्ट MIT License के तहत है.

GN⁺ की संक्षिप्त जानकारी

  • WordLlama एक NLP टूल है जो बड़े language model के components को reuse करके efficient और compact word representations बनाता है.
  • यह CPU पर तेज़ी से चलता है और कई NLP tasks के लिए उपयुक्त एक "Swiss Army knife" utility की तरह इस्तेमाल किया जा सकता है.
  • Binary embedding model high dimensions में अधिक स्पष्ट सुधार दिखाता है, और 512 या 1024 dimensions की सिफारिश की जाती है.
  • अपनी तेज़ performance और portable size की वजह से यह exploratory analysis और utility applications में उपयोगी है.

1 टिप्पणियां

 
GN⁺ 2024-09-16
Hacker News राय
  • छोटा आकार पसंद आया, SBERT के सबसे छोटे मॉडल की तुलना में लाभदायक

    • तकनीकी रूप से पुराना है, लेकिन performance के लिए यह एक समझौता है
    • अलग-अलग similarity प्रकारों (जैसे semantic, NLI, noun-abstract) के बीच switch करने का तरीका देने का अनुरोध
    • उदाहरण के लिए, "Freezing" और "Burning" को अख़बार लेख classification में समान, लेकिन chemistry लेखों में विपरीत मानना चाहूँगा
    • NLI embeddings का उपयोग करके causal relationships को समझना चाहूँगा
    • SBERT बड़ा है और कई models लोड करने पड़ते हैं, इसलिए resource consumption अधिक है
  • embeddings बहुत-सी semantic जानकारी capture करते हैं और अपने आप में उपयोगी tasks के लिए इस्तेमाल किए जा सकते हैं

    • CLIP model के text encoder embeddings का उपयोग करके prompts को मजबूत किया जाता है
    • उदाहरण के लिए, यदि "building" शब्द दिया जाए, तो embedding matrix में "concrete", "underground" आदि ढूँढकर उन्हें replace या add किया जाता है
    • सीमित experiments में अधिकांश queries के लिए high recall मिला
  • पूछा गया कि क्या अंग्रेज़ी के अलावा अन्य भाषाओं के लिए भी कोई योजना है

    • फ़्रेंच के लिए यह एक बेहतरीन tool होगा
  • यह दिखाता है कि tokens में स्वयं बहुत-सा semantic content शामिल होता है

  • embeddings का उपयोग करके Little Alchemy को हल करने के बारे में विचार

  • game development में बहुत उपयोगी, धन्यवाद

  • बढ़िया लग रहा है, mini-lm model के फ़ायदों के बारे में सवाल

    • लगता है कि अधिकांश mteb tasks में बेहतर है, लेकिन inference आदि में भी बेहतर है या नहीं, यह जानना चाहूँगा
  • कुछ साल पहले इसी तरह की functionality का उपयोग करके एक "language game" लिखा था