stephenleo commited on
Commit
6988d55
1 Parent(s): d2b0a3c

adding model files locally for performance

Browse files
helpers.py CHANGED
@@ -40,7 +40,7 @@ def load_data(uploaded_file):
40
  @st.cache()
41
  def embedding_gen(data):
42
  logger.info('Calculating Embeddings')
43
- return SentenceTransformer('allenai-specter').encode(data['Text'])
44
 
45
 
46
  @st.cache()
 
40
  @st.cache()
41
  def embedding_gen(data):
42
  logger.info('Calculating Embeddings')
43
+ return SentenceTransformer('./sentence-transformers_allenai-specter').encode(data['Text'])
44
 
45
 
46
  @st.cache()
sentence-transformers_allenai-specter/.gitattributes ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
2
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.h5 filter=lfs diff=lfs merge=lfs -text
5
+ *.tflite filter=lfs diff=lfs merge=lfs -text
6
+ *.tar.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.ot filter=lfs diff=lfs merge=lfs -text
8
+ *.onnx filter=lfs diff=lfs merge=lfs -text
9
+ *.arrow filter=lfs diff=lfs merge=lfs -text
10
+ *.ftz filter=lfs diff=lfs merge=lfs -text
11
+ *.joblib filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.pb filter=lfs diff=lfs merge=lfs -text
15
+ *.pt filter=lfs diff=lfs merge=lfs -text
16
+ *.pth filter=lfs diff=lfs merge=lfs -text
sentence-transformers_allenai-specter/1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 768,
3
+ "pooling_mode_cls_token": true,
4
+ "pooling_mode_mean_tokens": false,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false
7
+ }
sentence-transformers_allenai-specter/README.md ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: sentence-similarity
3
+ tags:
4
+ - sentence-transformers
5
+ - feature-extraction
6
+ - sentence-similarity
7
+ license: apache-2.0
8
+ ---
9
+
10
+ # allenai-specter
11
+
12
+ This model is a conversion of the [AllenAI SPECTER](https://github.com/allenai/specter) model to [sentence-transformers](https://www.SBERT.net). It can be used to map the titles & abstracts of scientific publications to a vector space such that similar papers are close.
13
+
14
+
15
+ ## Usage (Sentence-Transformers)
16
+
17
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
18
+
19
+ ```
20
+ pip install -U sentence-transformers
21
+ ```
22
+
23
+ Then you can use the model like this:
24
+
25
+ ```python
26
+ from sentence_transformers import SentenceTransformer
27
+ sentences = ["This is an example sentence", "Each sentence is converted"]
28
+
29
+ model = SentenceTransformer('sentence-transformers/allenai-specter')
30
+ embeddings = model.encode(sentences)
31
+ print(embeddings)
32
+ ```
33
+
34
+
35
+
36
+ ## Usage (HuggingFace Transformers)
37
+ 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.
38
+
39
+ ```python
40
+ from transformers import AutoTokenizer, AutoModel
41
+ import torch
42
+
43
+
44
+ def cls_pooling(model_output, attention_mask):
45
+ return model_output[0][:,0]
46
+
47
+
48
+ # Sentences we want sentence embeddings for
49
+ sentences = ['This is an example sentence', 'Each sentence is converted']
50
+
51
+ # Load model from HuggingFace Hub
52
+ tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/allenai-specter')
53
+ model = AutoModel.from_pretrained('sentence-transformers/allenai-specter')
54
+
55
+ # Tokenize sentences
56
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
57
+
58
+ # Compute token embeddings
59
+ with torch.no_grad():
60
+ model_output = model(**encoded_input)
61
+
62
+ # Perform pooling. In this case, max pooling.
63
+ sentence_embeddings = cls_pooling(model_output, encoded_input['attention_mask'])
64
+
65
+ print("Sentence embeddings:")
66
+ print(sentence_embeddings)
67
+ ```
68
+
69
+
70
+
71
+ ## Evaluation Results
72
+
73
+
74
+
75
+ For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=sentence-transformers/allenai-specter)
76
+
77
+
78
+
79
+ ## Full Model Architecture
80
+ ```
81
+ SentenceTransformer(
82
+ (0): Transformer({'max_seq_length': 512, 'do_lower_case': False}) with Transformer model: BertModel
83
+ (1): Pooling({'word_embedding_dimension': 768, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
84
+ )
85
+ ```
86
+
87
+ ## Citing & Authors
88
+
89
+ See [AllenAI SPECTER](https://github.com/allenai/specter)
sentence-transformers_allenai-specter/config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "old_models/allenai-specter/0_Transformer",
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "gradient_checkpointing": false,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 768,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 3072,
13
+ "layer_norm_eps": 1e-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "transformers_version": "4.7.0",
21
+ "type_vocab_size": 2,
22
+ "use_cache": true,
23
+ "vocab_size": 31116
24
+ }
sentence-transformers_allenai-specter/config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.0.0",
4
+ "transformers": "4.7.0",
5
+ "pytorch": "1.9.0+cu102"
6
+ }
7
+ }
sentence-transformers_allenai-specter/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
+ ]
sentence-transformers_allenai-specter/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e5bc6960694f086334de21eae028f3b38439d3581a3f7bf87f71c91311961d34
3
+ size 439832305
sentence-transformers_allenai-specter/sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 512,
3
+ "do_lower_case": false
4
+ }
sentence-transformers_allenai-specter/special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]"}
sentence-transformers_allenai-specter/tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
sentence-transformers_allenai-specter/tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"do_lower_case": true, "unk_token": "[UNK]", "sep_token": "[SEP]", "pad_token": "[PAD]", "cls_token": "[CLS]", "mask_token": "[MASK]", "tokenize_chinese_chars": true, "strip_accents": null, "special_tokens_map_file": null, "name_or_path": "old_models/allenai-specter/0_Transformer", "do_basic_tokenize": true, "never_split": null}
sentence-transformers_allenai-specter/vocab.txt ADDED
The diff for this file is too large to render. See raw diff