brunokreiner
commited on
Commit
•
daab674
1
Parent(s):
7b1d0eb
Upload 10 files
Browse files- README.md +59 -151
- config.json +27 -0
- config_sentence_transformers.json +7 -0
- modules.json +14 -0
- pytorch_model.bin +3 -0
- sentence_bert_config.json +4 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +14 -0
- vocab.txt +0 -0
README.md
CHANGED
@@ -1,186 +1,94 @@
|
|
1 |
---
|
2 |
-
|
3 |
-
- en
|
4 |
tags:
|
5 |
-
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
10 |
-
|
11 |
-
Embeds song lyrics to 300 dimensions.
|
12 |
-
|
13 |
-
# Model Details
|
14 |
-
|
15 |
-
## Model Description
|
16 |
-
|
17 |
-
<!-- Provide a longer summary of what this model is. -->
|
18 |
-
|
19 |
-
- **Developed by:** [More Information Needed]
|
20 |
-
- **Shared by [optional]:** [More Information Needed]
|
21 |
-
- **Model type:** bert-base-uncased trained with contrastive learning
|
22 |
-
- **Language(s) (NLP):** [More Information Needed]
|
23 |
-
- **License:** [More Information Needed]
|
24 |
-
- **Finetuned from model [optional]:** [More Information Needed]
|
25 |
-
|
26 |
-
## Model Sources [optional]
|
27 |
-
|
28 |
-
<!-- Provide the basic links for the model. -->
|
29 |
-
|
30 |
-
- **Repository:** [More Information Needed]
|
31 |
-
- **Paper [optional]:** [More Information Needed]
|
32 |
-
- **Demo [optional]:** [More Information Needed]
|
33 |
-
|
34 |
-
# Uses
|
35 |
-
|
36 |
-
<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
|
37 |
-
|
38 |
-
## Direct Use
|
39 |
-
|
40 |
-
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
41 |
-
|
42 |
-
[More Information Needed]
|
43 |
-
|
44 |
-
## Downstream Use [optional]
|
45 |
-
|
46 |
-
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
47 |
-
|
48 |
-
[More Information Needed]
|
49 |
-
|
50 |
-
## Out-of-Scope Use
|
51 |
-
|
52 |
-
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
53 |
-
|
54 |
-
[More Information Needed]
|
55 |
-
|
56 |
-
# Bias, Risks, and Limitations
|
57 |
-
|
58 |
-
## Translate to English:
|
59 |
-
chlussendlich existieren die Lyrics für 606'255 Songs. Um das weitere Vorgehen zu vereinfachen, wurden diese Songs durch die Python-Implementierung eines in Java implementierten Google Sprachdetektors \cite{nakatani2010langdetect} \cite{langdetectpy} gefiltert und nur die verbleibenden 480'964 englischen Lyrics werden weiter beachtet.
|
60 |
-
|
61 |
-
\subsection{Weitere Probleme}
|
62 |
-
|
63 |
-
Im Nachhinein wurden 109 Lyrics festgestellt, die Spezialcharaktere haben, welche nicht vom Cleanup fetgestellt wurden. Diese wurden mit dem Regex \glqq '[a-zA-Z|\'|0-9]'\grqq{} gematcht und im Training ignoriert. Im Training wurden aber trotzdem einige Lyrics miteinberechnet, die zwar keine Spezialcharaktere haben, aber nicht ganz Englisch sind. Dadurch encoded das Languagemodel auch Japanische / Koreanische / Chinesische / Russische / Griechische sowie Spezialcharakter aus lateinischer Sprachen, jedoch mit sehr wenigen Trainingsdaten. Diese Lyrics wurden nicht durch das Google Spracherkennungsmodell als \glqq nicht Englisch\grqq{} eingestuft, weil sie genügend englische Wörter haben. Wir nehmen an, dass diese Lyrics das Training nicht gross beeinflussen und man kann von circa 500 solcher Songs ausgehen.
|
64 |
-
|
65 |
-
Einige Lyrics sind auch lateinigiserte Versionen von japanischen / koreanischen / chinesischen Lieder (manuell geprüft). Weitere Grenzfälle sind Lyrics mit akzentuierten Lyrics wie:
|
66 |
-
\\[8pt]
|
67 |
-
\glqq let your fists swang k i c k y o a s s oh yes k i c k y o a s s oh yes i say beat you say that ass\grqq{}
|
68 |
-
\\[8pt]
|
69 |
-
Eine Analyse fehlt über was genau mit diesen Wörtern im Embedding Space passiert.
|
70 |
-
|
71 |
-
## Recommendations
|
72 |
|
73 |
-
|
74 |
-
|
75 |
-
## How to Get Started with the Model
|
76 |
-
|
77 |
-
Use the code below to get started with the model.
|
78 |
-
|
79 |
-
[More Information Needed]
|
80 |
-
|
81 |
-
# Training Details
|
82 |
-
|
83 |
-
## Training Data
|
84 |
-
|
85 |
-
<!-- This should link to a Data Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
[More Information Needed]
|
90 |
-
|
91 |
-
## Training Procedure [optional]
|
92 |
-
|
93 |
-
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
94 |
-
|
95 |
-
### Preprocessing
|
96 |
-
|
97 |
-
[More Information Needed]
|
98 |
-
|
99 |
-
### Speeds, Sizes, Times
|
100 |
-
|
101 |
-
<!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
|
102 |
-
|
103 |
-
[More Information Needed]
|
104 |
-
|
105 |
-
# Evaluation
|
106 |
-
|
107 |
-
<!-- This section describes the evaluation protocols and provides the results. -->
|
108 |
-
|
109 |
-
## Testing Data, Factors & Metrics
|
110 |
-
|
111 |
-
### Testing Data
|
112 |
-
|
113 |
-
<!-- This should link to a Data Card if possible. -->
|
114 |
-
|
115 |
-
[More Information Needed]
|
116 |
-
|
117 |
-
### Factors
|
118 |
-
|
119 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
120 |
-
|
121 |
-
[More Information Needed]
|
122 |
|
123 |
-
|
124 |
|
125 |
-
|
126 |
|
127 |
-
|
128 |
|
129 |
-
##
|
130 |
|
131 |
-
|
132 |
|
133 |
-
|
|
|
|
|
134 |
|
|
|
135 |
|
|
|
|
|
|
|
136 |
|
137 |
-
|
|
|
|
|
|
|
138 |
|
139 |
-
<!-- Relevant interpretability work for the model goes here -->
|
140 |
|
141 |
-
[More Information Needed]
|
142 |
|
143 |
-
|
|
|
144 |
|
145 |
-
|
|
|
|
|
146 |
|
147 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
148 |
|
149 |
-
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
|
155 |
-
# Technical Specifications [optional]
|
156 |
|
157 |
-
|
|
|
158 |
|
159 |
-
|
|
|
|
|
160 |
|
161 |
-
|
|
|
162 |
|
163 |
-
|
|
|
|
|
164 |
|
165 |
-
|
|
|
166 |
|
167 |
-
|
|
|
|
|
168 |
|
169 |
-
### Software
|
170 |
|
171 |
-
[More Information Needed]
|
172 |
|
173 |
-
|
174 |
|
175 |
-
|
176 |
|
177 |
-
|
178 |
|
179 |
-
[More Information Needed]
|
180 |
|
181 |
-
# Model Card Contact
|
182 |
|
183 |
-
|
184 |
-
|
|
|
|
|
|
|
|
|
|
|
185 |
|
|
|
186 |
|
|
|
|
1 |
---
|
2 |
+
pipeline_tag: sentence-similarity
|
|
|
3 |
tags:
|
4 |
+
- sentence-transformers
|
5 |
+
- feature-extraction
|
6 |
+
- sentence-similarity
|
7 |
+
- transformers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
# {MODEL_NAME}
|
12 |
|
13 |
+
This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 300 dimensional dense vector space and can be used for tasks like clustering or semantic search.
|
14 |
|
15 |
+
<!--- Describe your model here -->
|
16 |
|
17 |
+
## Usage (Sentence-Transformers)
|
18 |
|
19 |
+
Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
|
20 |
|
21 |
+
```
|
22 |
+
pip install -U sentence-transformers
|
23 |
+
```
|
24 |
|
25 |
+
Then you can use the model like this:
|
26 |
|
27 |
+
```python
|
28 |
+
from sentence_transformers import SentenceTransformer
|
29 |
+
sentences = ["This is an example sentence", "Each sentence is converted"]
|
30 |
|
31 |
+
model = SentenceTransformer('{MODEL_NAME}')
|
32 |
+
embeddings = model.encode(sentences)
|
33 |
+
print(embeddings)
|
34 |
+
```
|
35 |
|
|
|
36 |
|
|
|
37 |
|
38 |
+
## Usage (HuggingFace Transformers)
|
39 |
+
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.
|
40 |
|
41 |
+
```python
|
42 |
+
from transformers import AutoTokenizer, AutoModel
|
43 |
+
import torch
|
44 |
|
|
|
45 |
|
46 |
+
#Mean Pooling - Take attention mask into account for correct averaging
|
47 |
+
def mean_pooling(model_output, attention_mask):
|
48 |
+
token_embeddings = model_output[0] #First element of model_output contains all token embeddings
|
49 |
+
input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
|
50 |
+
return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
|
51 |
|
|
|
52 |
|
53 |
+
# Sentences we want sentence embeddings for
|
54 |
+
sentences = ['This is an example sentence', 'Each sentence is converted']
|
55 |
|
56 |
+
# Load model from HuggingFace Hub
|
57 |
+
tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
|
58 |
+
model = AutoModel.from_pretrained('{MODEL_NAME}')
|
59 |
|
60 |
+
# Tokenize sentences
|
61 |
+
encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
|
62 |
|
63 |
+
# Compute token embeddings
|
64 |
+
with torch.no_grad():
|
65 |
+
model_output = model(**encoded_input)
|
66 |
|
67 |
+
# Perform pooling. In this case, mean pooling.
|
68 |
+
sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
|
69 |
|
70 |
+
print("Sentence embeddings:")
|
71 |
+
print(sentence_embeddings)
|
72 |
+
```
|
73 |
|
|
|
74 |
|
|
|
75 |
|
76 |
+
## Evaluation Results
|
77 |
|
78 |
+
<!--- Describe how your model was evaluated -->
|
79 |
|
80 |
+
For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name={MODEL_NAME})
|
81 |
|
|
|
82 |
|
|
|
83 |
|
84 |
+
## Full Model Architecture
|
85 |
+
```
|
86 |
+
SentenceTransformer(
|
87 |
+
(0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
|
88 |
+
(1): Pooling({'word_embedding_dimension': 300, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
|
89 |
+
)
|
90 |
+
```
|
91 |
|
92 |
+
## Citing & Authors
|
93 |
|
94 |
+
<!--- Describe where people can find more information -->
|
config.json
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "/notebooks/p5/lyrics-bert-new-90000/90000/0_SentenceTransformer/",
|
3 |
+
"add_cross_attention": true,
|
4 |
+
"architectures": [
|
5 |
+
"BertModel"
|
6 |
+
],
|
7 |
+
"attention_probs_dropout_prob": 0.1,
|
8 |
+
"classifier_dropout": null,
|
9 |
+
"hidden_act": "gelu",
|
10 |
+
"hidden_dropout_prob": 0.1,
|
11 |
+
"hidden_size": 300,
|
12 |
+
"initializer_range": 0.02,
|
13 |
+
"intermediate_size": 3072,
|
14 |
+
"is_decoder": true,
|
15 |
+
"layer_norm_eps": 1e-12,
|
16 |
+
"max_position_embeddings": 512,
|
17 |
+
"model_type": "bert",
|
18 |
+
"num_attention_heads": 2,
|
19 |
+
"num_hidden_layers": 2,
|
20 |
+
"pad_token_id": 0,
|
21 |
+
"position_embedding_type": "absolute",
|
22 |
+
"torch_dtype": "float32",
|
23 |
+
"transformers_version": "4.20.1",
|
24 |
+
"type_vocab_size": 2,
|
25 |
+
"use_cache": true,
|
26 |
+
"vocab_size": 52000
|
27 |
+
}
|
config_sentence_transformers.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"__version__": {
|
3 |
+
"sentence_transformers": "2.2.2",
|
4 |
+
"transformers": "4.20.1",
|
5 |
+
"pytorch": "1.12.0+cu116"
|
6 |
+
}
|
7 |
+
}
|
modules.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
[
|
2 |
+
{
|
3 |
+
"idx": 0,
|
4 |
+
"name": "0",
|
5 |
+
"path": "",
|
6 |
+
"type": "sentence_transformers.models.Transformer"
|
7 |
+
},
|
8 |
+
{
|
9 |
+
"idx": 1,
|
10 |
+
"name": "1",
|
11 |
+
"path": "1_Pooling",
|
12 |
+
"type": "sentence_transformers.models.Pooling"
|
13 |
+
}
|
14 |
+
]
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f9a2878052f3261475f932eccc2e45fd9159dd3b74e60d69bf5e8d6330b7a23c
|
3 |
+
size 83968433
|
sentence_bert_config.json
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"max_seq_length": 512,
|
3 |
+
"do_lower_case": false
|
4 |
+
}
|
special_tokens_map.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"mask_token": "[MASK]",
|
4 |
+
"pad_token": "[PAD]",
|
5 |
+
"sep_token": "[SEP]",
|
6 |
+
"unk_token": "[UNK]"
|
7 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"do_lower_case": true,
|
4 |
+
"mask_token": "[MASK]",
|
5 |
+
"model_max_length": 512,
|
6 |
+
"name_or_path": "/notebooks/p5/lyrics-bert-new-90000/90000/0_SentenceTransformer/",
|
7 |
+
"pad_token": "[PAD]",
|
8 |
+
"sep_token": "[SEP]",
|
9 |
+
"special_tokens_map_file": null,
|
10 |
+
"strip_accents": null,
|
11 |
+
"tokenize_chinese_chars": true,
|
12 |
+
"tokenizer_class": "BertTokenizer",
|
13 |
+
"unk_token": "[UNK]"
|
14 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|