Simplify usage; integrate Sentence Transformers (+ LlamaIndex/LangChain, etc.)

#5
by tomaarsen HF staff - opened

Hello!

Pull Request overview

  • Simplify usage; no more batch manipulation.
  • Integrate with Sentence Transformers
  • Fix README typos

Details

This PR intends to do 2 things: simplify the usage & integrate Sentence Transformers. Let's start with the first one.

batch_dict = tokenizer(input_texts, max_length=max_length, padding=True, truncation=True, return_tensors='pt')

Note that the performance is identical: still [[70.00666809082031, 8.184867858886719], [14.62420654296875, 77.71405792236328]] with the README script.


from sentence_transformers import SentenceTransformer

model = SentenceTransformer("Alibaba-NLP/gte-Qwen1.5-7B-instruct", trust_remote_code=True)
# In case you want to reduce the maximum length:
model.max_seq_length = 8192

queries = [
    "how much protein should a female eat",
    "summit define",
]
documents = [
    "As a general guideline, the CDC's average requirement of protein for women ages 19 to 70 is 46 grams per day. But, as you can see from this chart, you'll need to increase that if you're expecting or training for a marathon. Check out the chart below to see how much protein you should be eating each day.",
    "Definition of summit for English Language Learners. : 1  the highest point of a mountain : the top of a mountain. : 2  the highest level. : 3  a meeting or series of meetings between the leaders of two or more governments.",
]

query_embeddings = model.encode(queries, prompt_name="query")
document_embeddings = model.encode(documents)

scores = (query_embeddings @ document_embeddings.T) * 100
print(scores.tolist())
# [[70.00668334960938, 8.184843063354492], [14.62419319152832, 77.71407318115234]]

Lastly, I fixed some typos in the README and updated flash_attention to flash_attn, as the latter is the name of the Python package.

  • Tom Aarsen
tomaarsen changed pull request status to open
Alibaba-NLP org

Thank you for your suggestion, the modified gte-qwen1.5-7b-instruct model is now much more user-friendly!

zyznull changed pull request status to merged

Sign up or log in to comment