multi-train commited on
Commit
ce48b21
1 Parent(s): 7c65e1a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +20 -22
README.md CHANGED
@@ -2530,6 +2530,7 @@ The model is easy to use with **our customized** `sentence-transformer` library.
2530
 
2531
  **************************** **Updates** ****************************
2532
 
 
2533
  * 12/21: We released our [paper](https://arxiv.org/abs/2212.09741), [code](https://github.com/HKUNLP/instructor-embedding), [checkpoint](https://huggingface.co/hkunlp/instructor-xl) and [project page](https://instructor-embedding.github.io/)! Check them out!
2534
 
2535
  ## Quick start
@@ -2537,20 +2538,17 @@ The model is easy to use with **our customized** `sentence-transformer` library.
2537
 
2538
  ## Installation
2539
  ```bash
2540
- git clone https://github.com/HKUNLP/instructor-embedding
2541
- cd instructor-embedding
2542
- cd sentence-transformers
2543
- pip install -e .
2544
  ```
2545
 
2546
  ## Compute your customized embeddings
2547
  Then you can use the model like this to calculate domain-specific and task-aware embeddings:
2548
  ```python
2549
- from sentence_transformers import SentenceTransformer
 
2550
  sentence = "3D ActionSLAM: wearable person tracking in multi-floor environments"
2551
- instruction = "Represent the Science title; Input:"
2552
- model = SentenceTransformer('hkunlp/instructor-xl')
2553
- embeddings = model.encode([[instruction,sentence,0]])
2554
  print(embeddings)
2555
  ```
2556
 
@@ -2560,7 +2558,7 @@ print(embeddings)
2560
  ## Calculate embeddings for your customized texts
2561
  If you want to calculate customized embeddings for specific sentences, you may follow the unified template to write instructions:
2562
 
2563
-                           Represent the `domain` `text_type` for `task_objective`; Input:
2564
  * `domain` is optional, and it specifies the domain of the text, e.g., science, finance, medicine, etc.
2565
  * `text_type` is required, and it specifies the encoding unit, e.g., sentence, document, paragraph, etc.
2566
  * `task_objective` is optional, and it specifies the objective of embedding, e.g., retrieve a document, classify the sentence, etc.
@@ -2569,10 +2567,10 @@ If you want to calculate customized embeddings for specific sentences, you may f
2569
  You can further use the model to compute similarities between two groups of sentences, with **customized embeddings**.
2570
  ```python
2571
  from sklearn.metrics.pairwise import cosine_similarity
2572
- sentences_a = [['Represent the Science sentence; Input: ','Parton energy loss in QCD matter',0],
2573
- ['Represent the Financial statement; Input: ','The Federal Reserve on Wednesday raised its benchmark interest rate.',0]]
2574
- sentences_b = [['Represent the Science sentence; Input: ','The Chiral Phase Transition in Dissipative Dynamics', 0],
2575
- ['Represent the Financial statement; Input: ','The funds rose less than 0.5 per cent on Friday',0]]
2576
  embeddings_a = model.encode(sentences_a)
2577
  embeddings_b = model.encode(sentences_b)
2578
  similarities = cosine_similarity(embeddings_a,embeddings_b)
@@ -2584,10 +2582,10 @@ You can also use **customized embeddings** for information retrieval.
2584
  ```python
2585
  import numpy as np
2586
  from sklearn.metrics.pairwise import cosine_similarity
2587
- query = [['Represent the Wikipedia question for retrieving supporting documents; Input: ','where is the food stored in a yam plant',0]]
2588
- 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],
2589
- ['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],
2590
- ['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]]
2591
  query_embeddings = model.encode(query)
2592
  corpus_embeddings = model.encode(corpus)
2593
  similarities = cosine_similarity(query_embeddings,corpus_embeddings)
@@ -2599,11 +2597,11 @@ print(retrieved_doc_id)
2599
  Use **customized embeddings** for clustering texts in groups.
2600
  ```python
2601
  import sklearn.cluster
2602
- sentences = [['Represent the Medicine sentence for clustering; Input: ','Dynamical Scalar Degree of Freedom in Horava-Lifshitz Gravity', 0],
2603
- ['Represent the Medicine sentence for clustering; Input: ','Comparison of Atmospheric Neutrino Flux Calculations at Low Energies', 0],
2604
- ['Represent the Medicine sentence for clustering; Input: ','Fermion Bags in the Massive Gross-Neveu Model', 0],
2605
- ['Represent the Medicine sentence for clustering; Input: ',"QCD corrections to Associated t-tbar-H production at the Tevatron",0],
2606
- ['Represent the Medicine sentence for clustering; Input: ','A New Analysis of the R Measurements: Resonance Parameters of the Higher, Vector States of Charmonium',0]]
2607
  embeddings = model.encode(sentences)
2608
  clustering_model = sklearn.cluster.MiniBatchKMeans(n_clusters=2)
2609
  clustering_model.fit(embeddings)
 
2530
 
2531
  **************************** **Updates** ****************************
2532
 
2533
+ * 01/21: We released a new [checkpoint](https://huggingface.co/hkunlp/instructor-xl) trained with hard negatives, which gives better performance.
2534
  * 12/21: We released our [paper](https://arxiv.org/abs/2212.09741), [code](https://github.com/HKUNLP/instructor-embedding), [checkpoint](https://huggingface.co/hkunlp/instructor-xl) and [project page](https://instructor-embedding.github.io/)! Check them out!
2535
 
2536
  ## Quick start
 
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-xl')
2549
  sentence = "3D ActionSLAM: wearable person tracking in multi-floor environments"
2550
+ instruction = "Represent the Science title:"
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)