KDHyun08 commited on
Commit
199153e
โ€ข
1 Parent(s): 8affc14

Upload with huggingface_hub

Browse files
Files changed (2) hide show
  1. .gitignore +1 -1
  2. README.md +39 -81
.gitignore CHANGED
@@ -1 +1 @@
1
- README.md
 
1
+ ./README.md
README.md CHANGED
@@ -2,131 +2,89 @@
2
  pipeline_tag: sentence-similarity
3
  tags:
4
  - sentence-transformers
 
5
  - sentence-similarity
6
  - transformers
7
- - TAACO
8
- language: ko
9
  ---
10
 
11
- # TAACO_Similarity
12
 
13
- ๋ณธ ๋ชจ๋ธ์€ [Sentence-transformers](https://www.SBERT.net)๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•˜๋ฉฐ KLUE์˜ STS(Sentence Textual Similarity) ๋ฐ์ดํ„ฐ์…‹์„ ํ†ตํ•ด ํ›ˆ๋ จ์„ ์ง„ํ–‰ํ•œ ๋ชจ๋ธ์ž…๋‹ˆ๋‹ค.
14
- ํ•„์ž๊ฐ€ ์ œ์ž‘ํ•˜๊ณ  ์žˆ๋Š” ํ•œ๊ตญ์–ด ๋ฌธ์žฅ๊ฐ„ ๊ฒฐ์†์„ฑ ์ธก์ • ๋„๊ตฌ์ธ K-TAACO(๊ฐ€์ œ)์˜ ์ง€ํ‘œ ์ค‘ ํ•˜๋‚˜์ธ ๋ฌธ์žฅ ๊ฐ„ ์˜๋ฏธ์  ๊ฒฐ์†์„ฑ์„ ์ธก์ •ํ•˜๊ธฐ ์œ„ํ•ด ๋ณธ ๋ชจ๋ธ์„ ์ œ์ž‘ํ•˜์˜€์Šต๋‹ˆ๋‹ค.
15
- ๋˜ํ•œ ๋ชจ๋‘์˜ ๋ง๋ญ‰์น˜์˜ ๋ฌธ์žฅ๊ฐ„ ์œ ์‚ฌ๋„ ๋ฐ์ดํ„ฐ ๋“ฑ ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๊ตฌํ•ด ์ถ”๊ฐ€ ํ›ˆ๋ จ์„ ์ง„ํ–‰ํ•  ์˜ˆ์ •์ž…๋‹ˆ๋‹ค.
16
 
17
  ## Usage (Sentence-Transformers)
18
 
19
- ๋ณธ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” [Sentence-transformers](https://www.SBERT.net)๋ฅผ ์„ค์น˜ํ•˜์—ฌ์•ผ ํ•ฉ๋‹ˆ๋‹ค.
20
 
21
  ```
22
  pip install -U sentence-transformers
23
  ```
24
 
25
- ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์•„๋ž˜ ์ฝ”๋“œ๋ฅผ ์ฐธ์กฐํ•˜์‹œ๊ธธ ๋ฐ”๋ž๋‹ˆ๋‹ค.
26
 
27
  ```python
28
- from sentence_transformers import SentenceTransformer, models
29
  sentences = ["This is an example sentence", "Each sentence is converted"]
30
 
31
- embedding_model = models.Transformer(
32
- model_name_or_path="KDHyun08/TAACO_STS",
33
- max_seq_length=256,
34
- do_lower_case=True
35
- )
36
-
37
- pooling_model = models.Pooling(
38
- embedding_model.get_word_embedding_dimension(),
39
- pooling_mode_mean_tokens=True,
40
- pooling_mode_cls_token=False,
41
- pooling_mode_max_tokens=False,
42
- )
43
- model = SentenceTransformer(modules=[embedding_model, pooling_model])
44
-
45
  embeddings = model.encode(sentences)
46
  print(embeddings)
47
  ```
48
 
49
 
50
- ## Usage (์‹ค์ œ ๋ฌธ์žฅ ๊ฐ„ ์œ ์‚ฌ๋„ ๋น„๊ต)
51
- [Sentence-transformers](https://www.SBERT.net) ๋ฅผ ์„ค์น˜ํ•œ ํ›„ ์•„๋ž˜ ๋‚ด์šฉ๊ณผ ๊ฐ™์ด ๋ฌธ์žฅ ๊ฐ„ ์œ ์‚ฌ๋„๋ฅผ ๋น„๊ตํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
52
- query ๋ณ€์ˆ˜๋Š” ๋น„๊ต ๊ธฐ์ค€์ด ๋˜๋Š” ๋ฌธ์žฅ(Source Sentence)์ด๊ณ  ๋น„๊ต๋ฅผ ์ง„ํ–‰ํ•  ๋ฌธ์žฅ์€ docs์— list ํ˜•์‹์œผ๋กœ ๊ตฌ์„ฑํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.
53
-
54
- ```python
55
- from sentence_transformers import SentenceTransformer, models
56
-
57
- embedding_model = models.Transformer(
58
- model_name_or_path="KDHyun08/TAACO_STS",
59
- max_seq_length=256,
60
- do_lower_case=True
61
- )
62
-
63
- pooling_model = models.Pooling(
64
- embedding_model.get_word_embedding_dimension(),
65
- pooling_mode_mean_tokens=True,
66
- pooling_mode_cls_token=False,
67
- pooling_mode_max_tokens=False,
68
- )
69
- model = SentenceTransformer(modules=[embedding_model, pooling_model])
70
- docs = ['์–ด์ œ๋Š” ์•„๋‚ด์˜ ์ƒ์ผ์ด์—ˆ๋‹ค', '์ƒ์ผ์„ ๋งž์ดํ•˜์—ฌ ์•„์นจ์„ ์ค€๋น„ํ•˜๊ฒ ๋‹ค๊ณ  ์˜ค์ „ 8์‹œ 30๋ถ„๋ถ€ํ„ฐ ์Œ์‹์„ ์ค€๋น„ํ•˜์˜€๋‹ค. ์ฃผ๋œ ๋ฉ”๋‰ด๋Š” ์Šคํ…Œ์ดํฌ์™€ ๋‚™์ง€๋ณถ์Œ, ๋ฏธ์—ญ๊ตญ, ์žก์ฑ„, ์†Œ์•ผ ๋“ฑ์ด์—ˆ๋‹ค', '์Šคํ…Œ์ดํฌ๋Š” ์ž์ฃผ ํ•˜๋Š” ์Œ์‹์ด์–ด์„œ ์ž์‹ ์ด ์ค€๋น„ํ•˜๋ ค๊ณ  ํ–ˆ๋‹ค', '์•ž๋’ค๋„ 1๋ถ„์”ฉ 3๋ฒˆ ๋’ค์ง‘๊ณ  ๋ž˜์ŠคํŒ…์„ ์ž˜ ํ•˜๋ฉด ์œก์ฆ™์ด ๊ฐ€๋“ํ•œ ์Šคํ…Œ์ดํฌ๊ฐ€ ์ค€๋น„๋˜๋‹ค', '์•„๋‚ด๋„ ๊ทธ๋Ÿฐ ์Šคํ…Œ์ดํฌ๋ฅผ ์ข‹์•„ํ•œ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์ƒ์ƒ๋„ ๋ชปํ•œ ์ผ์ด ๋ฒŒ์ด์ง€๊ณ  ๋ง์•˜๋‹ค', '๋ณดํ†ต ์‹œ์ฆˆ๋‹์ด ๋˜์ง€ ์•Š์€ ์›์œก์„ ์‚ฌ์„œ ์Šคํ…Œ์ดํฌ๋ฅผ ํ–ˆ๋Š”๋ฐ, ์ด๋ฒˆ์—๋Š” ์‹œ์ฆˆ๋‹์ด ๋œ ๋ถ€์ฑ—์‚ด์„ ๊ตฌ์ž…ํ•ด์„œ ํ–ˆ๋‹ค', '๊ทธ๋Ÿฐ๋ฐ ์ผ€์ด์Šค ์•ˆ์— ๋ฐฉ๋ถ€์ œ๊ฐ€ ๋“ค์–ด์žˆ๋Š” ๊ฒƒ์„ ์ธ์ง€ํ•˜์ง€ ๋ชปํ•˜๊ณ  ๋ฐฉ๋ถ€์ œ์™€ ๋™์‹œ์— ํ”„๋ผ์ดํŒฌ์— ์˜ฌ๋ ค๋†“์„ ๊ฒƒ์ด๋‹ค', '๊ทธ๊ฒƒ๋„ ์ธ์ง€ ๋ชปํ•œ ์ฒด... ์•ž๋ฉด์„ ์„ผ ๋ถˆ์— 1๋ถ„์„ ๊ตฝ๊ณ  ๋’ค์ง‘๋Š” ์ˆœ๊ฐ„ ๋ฐฉ๋ถ€์ œ๊ฐ€ ํ•จ๊ป˜ ๊ตฌ์–ด์ง„ ๊ฒƒ์„ ์•Œ์•˜๋‹ค', '์•„๋‚ด์˜ ์ƒ์ผ์ด๋ผ ๋ง›์žˆ๊ฒŒ ๊ตฌ์›Œ๋ณด๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ ์–ด์ฒ˜๊ตฌ๋‹ˆ์—†๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๋‹ค', '๋ฐฉ๋ถ€์ œ๊ฐ€ ์„ผ ๋ถˆ์— ๋…น์•„์„œ ๊ทธ๋Ÿฐ์ง€ ๋ฌผ์ฒ˜๋Ÿผ ํ˜๋Ÿฌ๋‚ด๋ ธ๋‹ค', ' ๊ณ ๋ฏผ์„ ํ–ˆ๋‹ค. ๋ฐฉ๋ถ€์ œ๊ฐ€ ๋ฌป์€ ๋ถ€๋ฌธ๋งŒ ์ œ๊ฑฐํ•˜๊ณ  ๋‹ค์‹œ ๊ตฌ์šธ๊นŒ ํ–ˆ๋Š”๋ฐ ๋ฐฉ๋ถ€์ œ์— ์ ˆ๋Œ€ ๋จน์ง€ ๋ง๋ผ๋Š” ๋ฌธ๊ตฌ๊ฐ€ ์žˆ์–ด์„œ ์•„๊น์ง€๋งŒ ๋ฒ„๋ฆฌ๋Š” ๋ฐฉํ–ฅ์„ ํ–ˆ๋‹ค', '๋„ˆ๋ฌด๋‚˜ ์•ˆํƒ€๊นŒ์› ๋‹ค', '์•„์นจ ์ผ์ฐ ์•„๋‚ด๊ฐ€ ์ข‹์•„ํ•˜๋Š” ์Šคํ…Œ์ดํฌ๋ฅผ ์ค€๋น„ํ•˜๊ณ  ๊ทธ๊ฒƒ์„ ๋ง›์žˆ๊ฒŒ ๋จน๋Š” ์•„๋‚ด์˜ ๋ชจ์Šต์„ ๋ณด๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ ์ „ํ˜€ ์ƒ๊ฐ์ง€๋„ ๋ชปํ•œ ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•ด์„œ... ํ•˜์ง€๋งŒ ์ •์‹ ์„ ์ถ”์Šค๋ฅด๊ณ  ๋ฐ”๋กœ ๋‹ค๋ฅธ ๋ฉ”๋‰ด๋กœ ๋ณ€๊ฒฝํ–ˆ๋‹ค', '์†Œ์•ผ, ์†Œ์‹œ์ง€ ์•ผ์ฑ„๋ณถ์Œ..', '์•„๋‚ด๊ฐ€ ์ข‹์•„ํ•˜๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ ๋ƒ‰์žฅ๊ณ  ์•ˆ์— ์žˆ๋Š” ํ›„๋ž‘ํฌ์†Œ์„ธ์ง€๋ฅผ ๋ณด๋‹ˆ ๋ฐ”๋กœ ์†Œ์•ผ๋ฅผ ํ•ด์•ผ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๋‹ค. ์Œ์‹์€ ์„ฑ๊ณต์ ์œผ๋กœ ์™„์„ฑ์ด ๋˜์—ˆ๋‹ค', '40๋ฒˆ์งธ๋ฅผ ๋งž์ดํ•˜๋Š” ์•„๋‚ด์˜ ์ƒ์ผ์€ ์„ฑ๊ณต์ ์œผ๋กœ ์ค€๋น„๊ฐ€ ๋˜์—ˆ๋‹ค', '๋ง›์žˆ๊ฒŒ ๋จน์–ด ์ค€ ์•„๋‚ด์—๊ฒŒ๋„ ๊ฐ์‚ฌํ–ˆ๋‹ค', '๋งค๋…„ ์•„๋‚ด์˜ ์ƒ์ผ์— ๋งž์ดํ•˜๋ฉด ์•„์นจ๋งˆ๋‹ค ์ƒ์ผ์„ ์ฐจ๋ ค์•ผ๊ฒ ๋‹ค. ์˜ค๋Š˜๋„ ์ฆ๊ฑฐ์šด ํ•˜๋ฃจ๊ฐ€ ๋˜์—ˆ์œผ๋ฉด ์ข‹๊ฒ ๋‹ค', '๏ฟฝ๏ฟฝ๏ฟฝ์ผ์ด๋‹ˆ๊นŒ~']
71
- #๊ฐ ๋ฌธ์žฅ์˜ vector๊ฐ’ encoding
72
- document_embeddings = model.encode(docs)
73
 
74
- query = '์ƒ์ผ์„ ๋งž์ดํ•˜์—ฌ ์•„์นจ์„ ์ค€๋น„ํ•˜๊ฒ ๋‹ค๊ณ  ์˜ค์ „ 8์‹œ 30๋ถ„๋ถ€ํ„ฐ ์Œ์‹์„ ์ค€๋น„ํ•˜์˜€๋‹ค'
75
- query_embedding = model.encode(query)
76
 
77
- top_k = min(10, len(docs))
 
 
78
 
79
- # ์ฝ”์‚ฌ์ธ ์œ ์‚ฌ๋„ ๊ณ„์‚ฐ ํ›„,
80
- cos_scores = util.pytorch_cos_sim(query_embedding, document_embeddings)[0]
81
 
82
- # ์ฝ”์‚ฌ์ธ ์œ ์‚ฌ๋„ ์ˆœ์œผ๋กœ ๋ฌธ์žฅ ์ถ”์ถœ
83
- top_results = torch.topk(cos_scores, k=top_k)
 
 
 
84
 
85
- print(f"์ž…๋ ฅ ๋ฌธ์žฅ: {query}")
86
- print(f"\n<์ž…๋ ฅ ๋ฌธ์žฅ๊ณผ ์œ ์‚ฌํ•œ {top_k} ๊ฐœ์˜ ๋ฌธ์žฅ>\n")
87
 
88
- for i, (score, idx) in enumerate(zip(top_results[0], top_results[1])):
89
- print(f"{i+1}: {docs[idx]} {'(์œ ์‚ฌ๋„: {:.4f})'.format(score)}\n")
90
- ```
91
 
 
 
 
92
 
 
 
93
 
94
- ## Evaluation Results
 
 
95
 
96
- ์œ„ ์˜ˆ์‹œ(Usage)๋ฅผ ์‹คํ–‰ํ•˜๊ฒŒ ๋˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์€ ๊ฒฐ๊ณผ๊ฐ€ ๋„์ถœ๋ฉ๋‹ˆ๋‹ค. 1์— ๊ฐ€๊นŒ์šธ์ˆ˜๋ก ์œ ์‚ฌํ•œ ๋ฌธ์žฅ์ž…๋‹ˆ๋‹ค.
 
97
 
 
 
98
  ```
99
- ์ž…๋ ฅ ๋ฌธ์žฅ: ์ƒ์ผ์„ ๋งž์ดํ•˜์—ฌ ์•„์นจ์„ ์ค€๋น„ํ•˜๊ฒ ๋‹ค๊ณ  ์˜ค์ „ 8์‹œ 30๋ถ„๋ถ€ํ„ฐ ์Œ์‹์„ ์ค€๋น„ํ•˜์˜€๋‹ค
100
-
101
- <์ž…๋ ฅ ๋ฌธ์žฅ๊ณผ ์œ ์‚ฌํ•œ 10 ๊ฐœ์˜ ๋ฌธ์žฅ>
102
-
103
- 1: ์ƒ์ผ์„ ๋งž์ดํ•˜์—ฌ ์•„์นจ์„ ์ค€๋น„ํ•˜๊ฒ ๋‹ค๊ณ  ์˜ค์ „ 8์‹œ 30๋ถ„๋ถ€ํ„ฐ ์Œ์‹์„ ์ค€๋น„ํ•˜์˜€๋‹ค. ์ฃผ๋œ ๋ฉ”๋‰ด๋Š” ์Šคํ…Œ์ดํฌ์™€ ๋‚™์ง€๋ณถ์Œ, ๋ฏธ์—ญ๊ตญ, ์žก์ฑ„, ์†Œ์•ผ ๋“ฑ์ด์—ˆ๋‹ค (์œ ์‚ฌ๋„: 0.6687)
104
 
105
- 2: ๋งค๋…„ ์•„๋‚ด์˜ ์ƒ์ผ์— ๋งž์ดํ•˜๋ฉด ์•„์นจ๋งˆ๋‹ค ์ƒ์ผ์„ ์ฐจ๋ ค์•ผ๊ฒ ๋‹ค. ์˜ค๋Š˜๋„ ์ฆ๊ฑฐ์šด ํ•˜๋ฃจ๊ฐ€ ๋˜์—ˆ์œผ๋ฉด ์ข‹๊ฒ ๋‹ค (์œ ์‚ฌ๋„: 0.6468)
106
 
107
- 3: 40๋ฒˆ์งธ๋ฅผ ๋งž์ดํ•˜๋Š” ์•„๋‚ด์˜ ์ƒ์ผ์€ ์„ฑ๊ณต์ ์œผ๋กœ ์ค€๋น„๊ฐ€ ๋˜์—ˆ๋‹ค (์œ ์‚ฌ๋„: 0.4647)
108
 
109
- 4: ์•„๋‚ด์˜ ์ƒ์ผ์ด๋ผ ๋ง›์žˆ๊ฒŒ ๊ตฌ์›Œ๋ณด๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ ์–ด์ฒ˜๊ตฌ๋‹ˆ์—†๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•œ ๊ฒƒ์ด๋‹ค (์œ ์‚ฌ๋„: 0.4469)
110
-
111
- 5: ์ƒ์ผ์ด๋‹ˆ๊นŒ~ (์œ ์‚ฌ๋„: 0.4218)
112
-
113
- 6: ์–ด์ œ๋Š” ์•„๋‚ด์˜ ์ƒ์ผ์ด์—ˆ๋‹ค (์œ ์‚ฌ๋„: 0.4192)
114
-
115
- 7: ์•„์นจ ์ผ์ฐ ์•„๋‚ด๊ฐ€ ์ข‹์•„ํ•˜๋Š” ์Šคํ…Œ์ดํฌ๋ฅผ ์ค€๋น„ํ•˜๊ณ  ๊ทธ๊ฒƒ์„ ๋ง›์žˆ๊ฒŒ ๋จน๋Š” ์•„๋‚ด์˜ ๋ชจ์Šต์„ ๋ณด๊ณ  ์‹ถ์—ˆ๋Š”๋ฐ ์ „ํ˜€ ์ƒ๊ฐ์ง€๋„ ๋ชปํ•œ ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•ด์„œ... ํ•˜์ง€๋งŒ ์ •์‹ ์„ ์ถ”์Šค๋ฅด๊ณ  ๋ฐ”๋กœ ๋‹ค๋ฅธ ๋ฉ”๋‰ด๋กœ ๋ณ€๊ฒฝํ–ˆ๋‹ค (์œ ์‚ฌ๋„: 0.4156)
116
 
117
- 8: ๋ง›์žˆ๊ฒŒ ๋จน์–ด ์ค€ ์•„๋‚ด์—๊ฒŒ๋„ ๊ฐ์‚ฌํ–ˆ๋‹ค (์œ ์‚ฌ๋„: 0.3093)
118
 
119
- 9: ์•„๋‚ด๊ฐ€ ์ข‹์•„ํ•˜๋Š”์ง€ ๋ชจ๋ฅด๊ฒ ์ง€๋งŒ ๋ƒ‰์žฅ๊ณ  ์•ˆ์— ์žˆ๋Š” ํ›„๋ž‘ํฌ์†Œ์„ธ์ง€๋ฅผ ๋ณด๋‹ˆ ๋ฐ”๋กœ ์†Œ์•ผ๋ฅผ ํ•ด์•ผ๊ฒ ๋‹ค๋Š” ์ƒ๊ฐ์ด ๋“ค์—ˆ๋‹ค. ์Œ์‹์€ ์„ฑ๊ณต์ ์œผ๋กœ ์™„์„ฑ์ด ๋˜์—ˆ๋‹ค (์œ ์‚ฌ๋„: 0.2259)
120
 
121
- 10: ์•„๋‚ด๋„ ๊ทธ๋Ÿฐ ์Šคํ…Œ์ดํฌ๋ฅผ ์ข‹์•„ํ•œ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ ์ƒ์ƒ๋„ ๋ชปํ•œ ์ผ์ด ๋ฒŒ์ด์ง€๊ณ  ๋ง์•˜๋‹ค (์œ ์‚ฌ๋„: 0.1967)
122
- ```
123
 
124
  ## Training
125
  The model was trained with the parameters:
126
 
127
  **DataLoader**:
128
 
129
- `torch.utils.data.dataloader.DataLoader` of length 142 with parameters:
130
  ```
131
  {'batch_size': 32, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
132
  ```
@@ -139,7 +97,7 @@ Parameters of the fit()-Method:
139
  ```
140
  {
141
  "epochs": 4,
142
- "evaluation_steps": 1000,
143
  "evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
144
  "max_grad_norm": 1,
145
  "optimizer_class": "<class 'transformers.optimization.AdamW'>",
@@ -157,7 +115,7 @@ Parameters of the fit()-Method:
157
  ## Full Model Architecture
158
  ```
159
  SentenceTransformer(
160
- (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
161
  (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
162
  )
163
  ```
 
2
  pipeline_tag: sentence-similarity
3
  tags:
4
  - sentence-transformers
5
+ - feature-extraction
6
  - sentence-similarity
7
  - transformers
 
 
8
  ---
9
 
10
+ # {MODEL_NAME}
11
 
12
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 768 dimensional dense vector space and can be used for tasks like clustering or semantic search.
13
+
14
+ <!--- Describe your model here -->
15
 
16
  ## Usage (Sentence-Transformers)
17
 
18
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
19
 
20
  ```
21
  pip install -U sentence-transformers
22
  ```
23
 
24
+ Then you can use the model like this:
25
 
26
  ```python
27
+ from sentence_transformers import SentenceTransformer
28
  sentences = ["This is an example sentence", "Each sentence is converted"]
29
 
30
+ model = SentenceTransformer('{MODEL_NAME}')
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  embeddings = model.encode(sentences)
32
  print(embeddings)
33
  ```
34
 
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ ## Usage (HuggingFace Transformers)
38
+ Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
39
 
40
+ ```python
41
+ from transformers import AutoTokenizer, AutoModel
42
+ import torch
43
 
 
 
44
 
45
+ #Mean Pooling - Take attention mask into account for correct averaging
46
+ def mean_pooling(model_output, attention_mask):
47
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
48
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
49
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
50
 
 
 
51
 
52
+ # Sentences we want sentence embeddings for
53
+ sentences = ['This is an example sentence', 'Each sentence is converted']
 
54
 
55
+ # Load model from HuggingFace Hub
56
+ tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
57
+ model = AutoModel.from_pretrained('{MODEL_NAME}')
58
 
59
+ # Tokenize sentences
60
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
61
 
62
+ # Compute token embeddings
63
+ with torch.no_grad():
64
+ model_output = model(**encoded_input)
65
 
66
+ # Perform pooling. In this case, mean pooling.
67
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
68
 
69
+ print("Sentence embeddings:")
70
+ print(sentence_embeddings)
71
  ```
 
 
 
 
 
72
 
 
73
 
 
74
 
75
+ ## Evaluation Results
 
 
 
 
 
 
76
 
77
+ <!--- Describe how your model was evaluated -->
78
 
79
+ For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name={MODEL_NAME})
80
 
 
 
81
 
82
  ## Training
83
  The model was trained with the parameters:
84
 
85
  **DataLoader**:
86
 
87
+ `torch.utils.data.dataloader.DataLoader` of length 25255 with parameters:
88
  ```
89
  {'batch_size': 32, 'sampler': 'torch.utils.data.sampler.RandomSampler', 'batch_sampler': 'torch.utils.data.sampler.BatchSampler'}
90
  ```
 
97
  ```
98
  {
99
  "epochs": 4,
100
+ "evaluation_steps": 808146,
101
  "evaluator": "sentence_transformers.evaluation.EmbeddingSimilarityEvaluator.EmbeddingSimilarityEvaluator",
102
  "max_grad_norm": 1,
103
  "optimizer_class": "<class 'transformers.optimization.AdamW'>",
 
115
  ## Full Model Architecture
116
  ```
117
  SentenceTransformer(
118
+ (0): Transformer({'max_seq_length': 256, 'do_lower_case': True}) with Transformer model: BertModel
119
  (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
120
  )
121
  ```