multi-train commited on
Commit
6a81ee9
1 Parent(s): eecd959

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +18 -21
README.md CHANGED
@@ -2538,20 +2538,17 @@ The model is easy to use with **our customized** `sentence-transformer` library.
2538
 
2539
  ## Installation
2540
  ```bash
2541
- git clone https://github.com/HKUNLP/instructor-embedding
2542
- cd instructor-embedding
2543
- cd sentence-transformers
2544
- pip install -e .
2545
  ```
2546
 
2547
  ## Compute your customized embeddings
2548
  Then you can use the model like this to calculate domain-specific and task-aware embeddings:
2549
  ```python
2550
- from sentence_transformers import SentenceTransformer
 
2551
  sentence = "3D ActionSLAM: wearable person tracking in multi-floor environments"
2552
  instruction = "Represent the Science title; Input:"
2553
- model = SentenceTransformer('hkunlp/instructor-large')
2554
- embeddings = model.encode([[instruction,sentence,0]])
2555
  print(embeddings)
2556
  ```
2557
 
@@ -2561,7 +2558,7 @@ print(embeddings)
2561
  ## Calculate embeddings for your customized texts
2562
  If you want to calculate customized embeddings for specific sentences, you may follow the unified template to write instructions:
2563
 
2564
-                           Represent the `domain` `text_type` for `task_objective`; Input:
2565
  * `domain` is optional, and it specifies the domain of the text, e.g., science, finance, medicine, etc.
2566
  * `text_type` is required, and it specifies the encoding unit, e.g., sentence, document, paragraph, etc.
2567
  * `task_objective` is optional, and it specifies the objective of embedding, e.g., retrieve a document, classify the sentence, etc.
@@ -2570,10 +2567,10 @@ If you want to calculate customized embeddings for specific sentences, you may f
2570
  You can further use the model to compute similarities between two groups of sentences, with **customized embeddings**.
2571
  ```python
2572
  from sklearn.metrics.pairwise import cosine_similarity
2573
- sentences_a = [['Represent the Science sentence; Input: ','Parton energy loss in QCD matter',0],
2574
- ['Represent the Financial statement; Input: ','The Federal Reserve on Wednesday raised its benchmark interest rate.',0]]
2575
- sentences_b = [['Represent the Science sentence; Input: ','The Chiral Phase Transition in Dissipative Dynamics', 0],
2576
- ['Represent the Financial statement; Input: ','The funds rose less than 0.5 per cent on Friday',0]]
2577
  embeddings_a = model.encode(sentences_a)
2578
  embeddings_b = model.encode(sentences_b)
2579
  similarities = cosine_similarity(embeddings_a,embeddings_b)
@@ -2585,10 +2582,10 @@ You can also use **customized embeddings** for information retrieval.
2585
  ```python
2586
  import numpy as np
2587
  from sklearn.metrics.pairwise import cosine_similarity
2588
- query = [['Represent the Wikipedia question for retrieving supporting documents; Input: ','where is the food stored in a yam plant',0]]
2589
- corpus = [['Represent the Wikipedia document for retrieval; Input: ','Capitalism has been dominant in the Western world since the end of feudalism, but most feel[who?] that the term "mixed economies" more precisely describes most contemporary economies, due to their containing both private-owned and state-owned enterprises. In capitalism, prices determine the demand-supply scale. For example, higher demand for certain goods and services lead to higher prices and lower demand for certain goods lead to lower prices.', 0],
2590
- ['Represent the Wikipedia document for retrieval; Input: ',"The disparate impact theory is especially controversial under the Fair Housing Act because the Act regulates many activities relating to housing, insurance, and mortgage loans—and some scholars have argued that the theory's use under the Fair Housing Act, combined with extensions of the Community Reinvestment Act, contributed to rise of sub-prime lending and the crash of the U.S. housing market and ensuing global economic recession",0],
2591
- ['Represent the Wikipedia document for retrieval; Input: ','Disparate impact in United States labor law refers to practices in employment, housing, and other areas that adversely affect one group of people of a protected characteristic more than another, even though rules applied by employers or landlords are formally neutral. Although the protected classes vary by statute, most federal civil rights laws protect based on race, color, religion, national origin, and sex as protected traits, and some laws include disability status and other traits as well.',0]]
2592
  query_embeddings = model.encode(query)
2593
  corpus_embeddings = model.encode(corpus)
2594
  similarities = cosine_similarity(query_embeddings,corpus_embeddings)
@@ -2600,11 +2597,11 @@ print(retrieved_doc_id)
2600
  Use **customized embeddings** for clustering texts in groups.
2601
  ```python
2602
  import sklearn.cluster
2603
- sentences = [['Represent the Medicine sentence for clustering; Input: ','Dynamical Scalar Degree of Freedom in Horava-Lifshitz Gravity', 0],
2604
- ['Represent the Medicine sentence for clustering; Input: ','Comparison of Atmospheric Neutrino Flux Calculations at Low Energies', 0],
2605
- ['Represent the Medicine sentence for clustering; Input: ','Fermion Bags in the Massive Gross-Neveu Model', 0],
2606
- ['Represent the Medicine sentence for clustering; Input: ',"QCD corrections to Associated t-tbar-H production at the Tevatron",0],
2607
- ['Represent the Medicine sentence for clustering; Input: ','A New Analysis of the R Measurements: Resonance Parameters of the Higher, Vector States of Charmonium',0]]
2608
  embeddings = model.encode(sentences)
2609
  clustering_model = sklearn.cluster.MiniBatchKMeans(n_clusters=2)
2610
  clustering_model.fit(embeddings)
 
2538
 
2539
  ## Installation
2540
  ```bash
2541
+ pip install InstructorEmbedding
 
 
 
2542
  ```
2543
 
2544
  ## Compute your customized embeddings
2545
  Then you can use the model like this to calculate domain-specific and task-aware embeddings:
2546
  ```python
2547
+ from InstructorEmbedding import INSTRUCTOR
2548
+ model = INSTRUCTOR('hkunlp/instructor-large')
2549
  sentence = "3D ActionSLAM: wearable person tracking in multi-floor environments"
2550
  instruction = "Represent the Science title; Input:"
2551
+ embeddings = model.encode([[instruction,sentence]])
 
2552
  print(embeddings)
2553
  ```
2554
 
 
2558
  ## Calculate embeddings for your customized texts
2559
  If you want to calculate customized embeddings for specific sentences, you may follow the unified template to write instructions:
2560
 
2561
+                           Represent the `domain` `text_type` for `task_objective`:
2562
  * `domain` is optional, and it specifies the domain of the text, e.g., science, finance, medicine, etc.
2563
  * `text_type` is required, and it specifies the encoding unit, e.g., sentence, document, paragraph, etc.
2564
  * `task_objective` is optional, and it specifies the objective of embedding, e.g., retrieve a document, classify the sentence, etc.
 
2567
  You can further use the model to compute similarities between two groups of sentences, with **customized embeddings**.
2568
  ```python
2569
  from sklearn.metrics.pairwise import cosine_similarity
2570
+ sentences_a = [['Represent the Science sentence: ','Parton energy loss in QCD matter'],
2571
+ ['Represent the Financial statement: ','The Federal Reserve on Wednesday raised its benchmark interest rate.']]
2572
+ sentences_b = [['Represent the Science sentence: ','The Chiral Phase Transition in Dissipative Dynamics'],
2573
+ ['Represent the Financial statement: ','The funds rose less than 0.5 per cent on Friday']]
2574
  embeddings_a = model.encode(sentences_a)
2575
  embeddings_b = model.encode(sentences_b)
2576
  similarities = cosine_similarity(embeddings_a,embeddings_b)
 
2582
  ```python
2583
  import numpy as np
2584
  from sklearn.metrics.pairwise import cosine_similarity
2585
+ query = [['Represent the Wikipedia question for retrieving supporting documents: ','where is the food stored in a yam plant']]
2586
+ corpus = [['Represent the Wikipedia document for retrieval: ','Capitalism has been dominant in the Western world since the end of feudalism, but most feel[who?] that the term "mixed economies" more precisely describes most contemporary economies, due to their containing both private-owned and state-owned enterprises. In capitalism, prices determine the demand-supply scale. For example, higher demand for certain goods and services lead to higher prices and lower demand for certain goods lead to lower prices.'],
2587
+ ['Represent the Wikipedia document for retrieval: ',"The disparate impact theory is especially controversial under the Fair Housing Act because the Act regulates many activities relating to housing, insurance, and mortgage loans—and some scholars have argued that the theory's use under the Fair Housing Act, combined with extensions of the Community Reinvestment Act, contributed to rise of sub-prime lending and the crash of the U.S. housing market and ensuing global economic recession"],
2588
+ ['Represent the Wikipedia document for retrieval: ','Disparate impact in United States labor law refers to practices in employment, housing, and other areas that adversely affect one group of people of a protected characteristic more than another, even though rules applied by employers or landlords are formally neutral. Although the protected classes vary by statute, most federal civil rights laws protect based on race, color, religion, national origin, and sex as protected traits, and some laws include disability status and other traits as well.']]
2589
  query_embeddings = model.encode(query)
2590
  corpus_embeddings = model.encode(corpus)
2591
  similarities = cosine_similarity(query_embeddings,corpus_embeddings)
 
2597
  Use **customized embeddings** for clustering texts in groups.
2598
  ```python
2599
  import sklearn.cluster
2600
+ sentences = [['Represent the Medicine sentence for clustering: ','Dynamical Scalar Degree of Freedom in Horava-Lifshitz Gravity'],
2601
+ ['Represent the Medicine sentence for clustering: ','Comparison of Atmospheric Neutrino Flux Calculations at Low Energies'],
2602
+ ['Represent the Medicine sentence for clustering: ','Fermion Bags in the Massive Gross-Neveu Model'],
2603
+ ['Represent the Medicine sentence for clustering: ',"QCD corrections to Associated t-tbar-H production at the Tevatron"],
2604
+ ['Represent the Medicine sentence for clustering: ','A New Analysis of the R Measurements: Resonance Parameters of the Higher, Vector States of Charmonium']]
2605
  embeddings = model.encode(sentences)
2606
  clustering_model = sklearn.cluster.MiniBatchKMeans(n_clusters=2)
2607
  clustering_model.fit(embeddings)