Skip to content

Commit eb4d32c

Browse files
authored
Update README.md
1 parent f3f191a commit eb4d32c

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

README.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ harmony.download_models()
5050

5151
```
5252
instruments = harmony.example_instruments["CES_D English"], harmony.example_instruments["GAD-7 Portuguese"]
53-
questions, similarity, query_similarity = harmony.match_instruments(instruments)
53+
questions, similarity, query_similarity, new_vectors_dict = harmony.match_instruments(instruments)
5454
```
5555

5656
## How to load a PDF, Excel or Word into an instrument
@@ -91,6 +91,30 @@ all_questions, similarity, query_similarity = match_instruments(instruments)
9191
* `all_questions` is a list of the questions passed to Harmony, in order.
9292
* `similarity` is the similarity matrix returned by Harmony.
9393
* `query_similarity` is the degree of similarity of each item to an optional query passed as argument to `match_instruments`.
94+
95+
## Using a different vectorisation function
96+
97+
Harmony defaults to `sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2` ([HuggingFace link](https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2)). However you can use other sentence transformers from HuggingFace by setting the environment `HARMONY_SENTENCE_TRANSFORMER_PATH` before importing Harmony:
98+
99+
```
100+
export HARMONY_SENTENCE_TRANSFORMER_PATH=sentence-transformers/distiluse-base-multilingual-cased-v2
101+
```
102+
103+
## Using OpenAI or other LLMs for vectorisation
104+
105+
Any word vector representation can be used by Harmony. The below example works for OpenAI's [text-embedding-ada-002](https://openai.com/blog/new-and-improved-embedding-model) model as of July 2023, provided you have create a paid OpenAI account. However, since LLMs are progressing rapidly, we have chosen not to integrate Harmony directly into the OpenAI client libraries, but instead allow you to pass Harmony any vectorisation function of your choice.
106+
107+
```
108+
import openai
109+
import numpy as np
110+
from harmony import match_instruments_with_function, example_instruments
111+
model_name = "text-embedding-ada-002"
112+
def convert_texts_to_vector(texts):
113+
vectors = openai.Embedding.create(input = texts, model=model_name)['data']
114+
return [vectors[i]["embedding"] for i in range(len(vectors))]
115+
instruments = example_instruments["CES_D English"], example_instruments["GAD-7 Portuguese"]
116+
all_questions, similarity, query_similarity, new_vectors_dict = match_instruments_with_function(instruments, None, convert_texts_to_vector)
117+
```
94118

95119
## Do you want to run Harmony in your browser locally?
96120

0 commit comments

Comments
 (0)