MCPcopy Create free account
hub / github.com/boyiwei/alignment-attribution-code / get_sentence_embedding

Function get_sentence_embedding

lib/eval.py:68–77  ·  view source on GitHub ↗
(model, tokenizer, sentence)

Source from the content-addressed store, hash-verified

66
67
68def get_sentence_embedding(model, tokenizer, sentence):
69 sentence = sentence.strip().replace('"', "")
70 word_embeddings = model.get_input_embeddings()
71
72 # Embed the sentence
73 tokenized = tokenizer(sentence, return_tensors="pt", add_special_tokens=False).to(
74 model.device
75 )
76 embedded = word_embeddings(tokenized.input_ids)
77 return embedded
78
79
80# Function to evaluate perplexity (ppl) on a specified model and tokenizer

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected