Views
No views yet
AutoModel:1from transformers import AutoModelForSequenceClassification
2model = AutoModelForSequenceClassification.from_pretrained(
3 "togethercomputer/m2-bert-80M-32k-retrieval",
4 trust_remote_code=True
5)1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
3max_seq_length = 32768
4testing_string = "Every morning, I make a cup of coffee to start my day."
5model = AutoModelForSequenceClassification.from_pretrained(
6 "togethercomputer/m2-bert-80M-32k-retrieval",
7 trust_remote_code=True
8)
9
10tokenizer = AutoTokenizer.from_pretrained(
11 "bert-base-uncased",
12 model_max_length=max_seq_length
13)
14input_ids = tokenizer(
15 [testing_string],
16 return_tensors="pt",
17 padding="max_length",
18 return_token_type_ids=False,
19 truncation=True,
20 max_length=max_seq_length
21)
22
23outputs = model(**input_ids)
24embeddings = outputs['sentence_embedding']1import os
2import requests
3
4def generate_together_embeddings(text: str, model_api_string: str, api_key: str):
5 url = "https://api.together.xyz/api/v1/embeddings"
6 headers = {
7 "accept": "application/json",
8 "content-type": "application/json",
9 "Authorization": f"Bearer {api_key}"
10 }
11 session = requests.Session()
12 response = session.post(
13 url,
14 headers=headers,
15 json={
16 "input": text,
17 "model": model_api_string
18 }
19 )
20 if response.status_code != 200:
21 raise ValueError(f"Request failed with status code {response.status_code}: {response.text}")
22 return response.json()['data'][0]['embedding']
23
24print(generate_together_embeddings(
25 'Hello world',
26 'togethercomputer/m2-bert-80M-32k-retrieval',
27 os.environ['TOGETHER_API_KEY'])[:10]
28)@inproceedings{fu2023monarch,
title={Monarch Mixer: A Simple Sub-Quadratic GEMM-Based Architecture},
author={Fu, Daniel Y and Arora, Simran and Grogan, Jessica and Johnson, Isys and Eyuboglu, Sabri and Thomas, Armin W and Spector, Benjamin and Poli, Michael and Rudra, Atri and R{\'e}, Christopher},
booktitle={Advances in Neural Information Processing Systems},
year={2023}
}