linhphanff commited on
Commit
72a5b6e
·
verified ·
1 Parent(s): e20d476

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +42 -0
README.md CHANGED
@@ -8,3 +8,45 @@ pipeline_tag: sentence-similarity
8
  tags:
9
  - cls token
10
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  tags:
9
  - cls token
10
  ---
11
+
12
+ ## <a name="sentences-transformers"></a> Using Semantic-base-vi with `transformers`
13
+
14
+ ### Installation <a name="install2"></a>
15
+ - Install `transformers`:
16
+
17
+ - `pip install -U transformers`
18
+
19
+ - Install `pyvi` for word segmentation:
20
+
21
+ - `pip install pyvi`
22
+
23
+ ### Example usage <a name="usage2"></a>
24
+
25
+ ```python
26
+ import torch
27
+ from transformers import AutoModel, AutoTokenizer
28
+ from pyvi.ViTokenizer import tokenize
29
+
30
+ tokenizer = AutoTokenizer.from_pretrained("linhphanff/semantic-base-vi")
31
+ model = AutoModel.from_pretrained("linhphanff/semantic-base-vi")
32
+
33
+ sentences = [
34
+ 'Học sinh cần được hướng dẫn kỹ năng học tập.',
35
+ 'Thời tiết hôm nay thật đẹp và mát mẻ.',
36
+ 'Công nghệ AI đang thay đổi thế giới từng ngày.',
37
+ 'Người dân đổ xô đi mua sắm dịp cuối năm.',
38
+ 'Giá xăng dầu giảm mạnh so với tháng trước.',
39
+ 'Chương trình khuyến mãi hấp dẫn đang diễn ra tại các siêu thị.',
40
+ 'Đội tuyển Việt Nam vô địch giải bóng đá Đông Nam Á.',
41
+ 'Thủ tướng phát biểu tại hội nghị quốc tế về môi trường.',
42
+ 'Nhiều tuyến đường ở thành phố Hồ Chí Minh bị ngập nặng sau cơn mưa lớn.',
43
+ 'Sách là nguồn tri thức vô giá cho mỗi con người.'
44
+ ]
45
+
46
+ sentences = [tokenize(sentence) for sentence in sentences]
47
+
48
+ inputs = tokenizer(sentences, padding=True, truncation=True, return_tensors="pt")
49
+
50
+ with torch.no_grad():
51
+ embeddings = model(**inputs, output_hidden_states=True, return_dict=True).pooler_output
52
+ ```