Update README.md
Browse files
README.md
CHANGED
@@ -24,6 +24,29 @@ tags:
|
|
24 |
|
25 |
- `pip install pyvi`
|
26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
## Usage with transformers
|
29 |
|
@@ -34,18 +57,10 @@ import torch
|
|
34 |
model = AutoModelForSequenceClassification.from_pretrained('itdainb/vietnamese-cross-encoder')
|
35 |
tokenizer = AutoTokenizer.from_pretrained('itdainb/vietnamese-cross-encoder')
|
36 |
|
37 |
-
features = tokenizer([
|
38 |
|
39 |
model.eval()
|
40 |
with torch.no_grad():
|
41 |
scores = model(**features).logits
|
42 |
print(scores)
|
43 |
-
```
|
44 |
-
|
45 |
-
## Usage with sentence-transformers
|
46 |
-
|
47 |
-
```python
|
48 |
-
from sentence_transformers import CrossEncoder
|
49 |
-
model = CrossEncoder('itdainb/vietnamese-cross-encoder', max_length=256)
|
50 |
-
scores = model.predict([('Query', 'Paragraph1'), ('Query', 'Paragraph2') , ('Query', 'Paragraph3')])
|
51 |
```
|
|
|
24 |
|
25 |
- `pip install pyvi`
|
26 |
|
27 |
+
## Pre-processing
|
28 |
+
|
29 |
+
```python
|
30 |
+
from pyvi import ViTokenizer
|
31 |
+
|
32 |
+
query = "UIT là gì?"
|
33 |
+
sentences = [
|
34 |
+
"UIT là Trường Đại học Công nghệ Thông tin (ĐH CNTT), Đại học Quốc gia Thành phố Hồ Chí Minh (ĐHQG-HCM)",
|
35 |
+
"Mô hình rerank — còn được gọi là cross-encoder — là một loại mô hình mà, khi được cung cấp một cặp truy vấn và tài liệu, sẽ đưa ra một điểm tương đồng.",
|
36 |
+
"Việt Nam, quốc hiệu là Cộng hòa xã hội chủ nghĩa Việt Nam, là một quốc gia xã hội chủ nghĩa nằm ở cực Đông của bán đảo Đông Dương thuộc khu vực Đông Nam Á"
|
37 |
+
]
|
38 |
+
|
39 |
+
tokenized_query = ViTokenizer.tokenize(query)
|
40 |
+
tokenized_sentences = [ViTokenizer.tokenize(sent) for sent in sentences]
|
41 |
+
```
|
42 |
+
|
43 |
+
## Usage with sentence-transformers
|
44 |
+
|
45 |
+
```python
|
46 |
+
from sentence_transformers import CrossEncoder
|
47 |
+
model = CrossEncoder('itdainb/vietnamese-cross-encoder', max_length=256)
|
48 |
+
scores = model.predict([(tokenized_query, sent) for sent in tokenized_sentences])
|
49 |
+
```
|
50 |
|
51 |
## Usage with transformers
|
52 |
|
|
|
57 |
model = AutoModelForSequenceClassification.from_pretrained('itdainb/vietnamese-cross-encoder')
|
58 |
tokenizer = AutoTokenizer.from_pretrained('itdainb/vietnamese-cross-encoder')
|
59 |
|
60 |
+
features = tokenizer([[tokenized_query, sent] for sent in tokenized_sentences], padding=True, truncation=True, return_tensors="pt")
|
61 |
|
62 |
model.eval()
|
63 |
with torch.no_grad():
|
64 |
scores = model(**features).logits
|
65 |
print(scores)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
```
|