Update README.md
Browse files
README.md
CHANGED
@@ -29,7 +29,11 @@ Below is an example and a set of functions to compute the cosine similarity betw
|
|
29 |
loads the model and tokenizer based on `model_name`. It returns a tuple containing the loaded model and tokenizer.
|
30 |
|
31 |
```python
|
32 |
-
from
|
|
|
|
|
|
|
|
|
33 |
|
34 |
def load_model_and_tokenizer(model_name: str) -> Tuple[AutoModel, AutoTokenizer]:
|
35 |
"""
|
@@ -114,6 +118,8 @@ Helper fn to compute and print out cosine similarity
|
|
114 |
|
115 |
|
116 |
```python
|
|
|
|
|
117 |
def calculate_cosine_similarity(embeddings: torch.Tensor, texts: List[str]) -> None:
|
118 |
"""
|
119 |
Calculate and print the cosine similarity between the first text and all other texts.
|
|
|
29 |
loads the model and tokenizer based on `model_name`. It returns a tuple containing the loaded model and tokenizer.
|
30 |
|
31 |
```python
|
32 |
+
from typing import List, Tuple
|
33 |
+
|
34 |
+
import torch
|
35 |
+
from transformers import AutoModel, AutoTokenizer
|
36 |
+
from transformers import AutoModelForTextEncoding
|
37 |
|
38 |
def load_model_and_tokenizer(model_name: str) -> Tuple[AutoModel, AutoTokenizer]:
|
39 |
"""
|
|
|
118 |
|
119 |
|
120 |
```python
|
121 |
+
from scipy.spatial.distance import cosine
|
122 |
+
|
123 |
def calculate_cosine_similarity(embeddings: torch.Tensor, texts: List[str]) -> None:
|
124 |
"""
|
125 |
Calculate and print the cosine similarity between the first text and all other texts.
|