ArvinZhuang
commited on
Commit
•
872b143
1
Parent(s):
b4f3820
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,54 @@
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: apache-2.0
|
3 |
---
|
4 |
+
|
5 |
+
To use the model, check vec2text repo [https://github.com/jxmorris12/vec2text](https://github.com/jxmorris12/vec2text)
|
6 |
+
|
7 |
+
# Example:
|
8 |
+
```python
|
9 |
+
from sentence_transformers import SentenceTransformer
|
10 |
+
import vec2text
|
11 |
+
import transformers
|
12 |
+
|
13 |
+
|
14 |
+
inversion_model = vec2text.models.InversionModel.from_pretrained(
|
15 |
+
"ielabgroup/vec2text_gtr-base-st_inversion"
|
16 |
+
)
|
17 |
+
model = vec2text.models.CorrectorEncoderModel.from_pretrained(
|
18 |
+
"ielabgroup/vec2text_gtr-base-st_corrector"
|
19 |
+
)
|
20 |
+
|
21 |
+
inversion_trainer = vec2text.trainers.InversionTrainer(
|
22 |
+
model=inversion_model,
|
23 |
+
train_dataset=None,
|
24 |
+
eval_dataset=None,
|
25 |
+
data_collator=transformers.DataCollatorForSeq2Seq(
|
26 |
+
inversion_model.tokenizer,
|
27 |
+
label_pad_token_id=-100,
|
28 |
+
),
|
29 |
+
)
|
30 |
+
|
31 |
+
model.config.dispatch_batches = None
|
32 |
+
corrector = vec2text.trainers.Corrector(
|
33 |
+
model=model,
|
34 |
+
inversion_trainer=inversion_trainer,
|
35 |
+
args=None,
|
36 |
+
data_collator=vec2text.collator.DataCollatorForCorrection(
|
37 |
+
tokenizer=inversion_trainer.model.tokenizer
|
38 |
+
),
|
39 |
+
)
|
40 |
+
|
41 |
+
model = SentenceTransformer('sentence-transformers/gtr-t5-base')
|
42 |
+
embeddings = model.encode([
|
43 |
+
"Jack Morris is a PhD student at Cornell Tech in New York City",
|
44 |
+
"It was the best of times, it was the worst of times, it was the age of wisdom, it was the age of foolishness, it was the epoch of belief, it was the epoch of incredulity"
|
45 |
+
], convert_to_tensor=True,).to('mps')
|
46 |
+
|
47 |
+
vec2text.invert_embeddings(
|
48 |
+
embeddings=embeddings,
|
49 |
+
corrector=corrector,
|
50 |
+
num_steps=20,
|
51 |
+
)
|
52 |
+
|
53 |
+
[' Jack Morris is a PhD student at Cornell Tech in New York', 'It was the best of times, it was the worst of times, it was the epoch of incredulity, it was age of']
|
54 |
+
```
|