bowphs commited on
Commit
153b714
1 Parent(s): eeed9e8

Add SPhilBerta files

Browse files
1_Pooling/config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 768,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": true,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false,
7
+ "pooling_mode_weightedmean_tokens": false,
8
+ "pooling_mode_lasttoken": false
9
+ }
README.md CHANGED
@@ -1,3 +1,87 @@
1
  ---
 
 
 
 
 
 
2
  license: apache-2.0
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ pipeline_tag: sentence-similarity
3
+ language:
4
+ - multilingual
5
+ - grc
6
+ - en
7
+ - la
8
  license: apache-2.0
9
+ tags:
10
+ - sentence-transformers
11
+ - sentence-similarity
12
  ---
13
+
14
+ # SPhilBerta
15
+
16
+ The paper [Exploring Language Models for Classical Philology](https://aclanthology.org/2023.acl-long.846/) is the first effort to systematically provide state-of-the-art language models for Classical Philology. Using PhilBERTa as a foundation, we introduce SPhilBERTa, a Sentence Transformer model to identify cross-lingual references between Latin and Ancient Greek texts. We employ the knowledge distillation method as proposed by [Reimers and Gurevych (2020)](https://aclanthology.org/2020.emnlp-main.365/). Our paper can be found [here](https://arxiv.org/abs/2308.12008).
17
+
18
+ ## Usage
19
+
20
+ ### Sentence-Transformers
21
+
22
+ When you have [sentence-transformers](https://www.SBERT.net) installed, you can use the model like this:
23
+
24
+ ```python
25
+ from sentence_transformers import SentenceTransformer
26
+ sentences = ["This is an example sentence", "Each sentence is converted"]
27
+
28
+ model = SentenceTransformer('{MODEL_NAME}')
29
+ embeddings = model.encode(sentences)
30
+ print(embeddings)
31
+ ```
32
+
33
+
34
+
35
+ ### HuggingFace Transformers
36
+ 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.
37
+
38
+ ```python
39
+ from transformers import AutoTokenizer, AutoModel
40
+ import torch
41
+
42
+
43
+ #Mean Pooling - Take attention mask into account for correct averaging
44
+ def mean_pooling(model_output, attention_mask):
45
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
46
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
47
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
48
+
49
+
50
+ # Sentences we want sentence embeddings for
51
+ sentences = ['This is an example sentence', 'Each sentence is converted']
52
+
53
+ # Load model from HuggingFace Hub
54
+ tokenizer = AutoTokenizer.from_pretrained('{MODEL_NAME}')
55
+ model = AutoModel.from_pretrained('{MODEL_NAME}')
56
+
57
+ # Tokenize sentences
58
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
59
+
60
+ # Compute token embeddings
61
+ with torch.no_grad():
62
+ model_output = model(**encoded_input)
63
+
64
+ # Perform pooling. In this case, mean pooling.
65
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
66
+
67
+ print("Sentence embeddings:")
68
+ print(sentence_embeddings)
69
+ ```
70
+
71
+ ## Contact
72
+ If you have any questions or problems, feel free to [reach out](mailto:riemenschneider@cl.uni-heidelberg.de).
73
+
74
+ ## Citation
75
+ ```bibtex
76
+ @incollection{riemenschneiderfrank:2023b,
77
+ author = "Riemenschneider, Frederick and Frank, Anette",
78
+ title = "{Graecia capta ferum victorem cepit. Detecting Latin Allusions to Ancient Greek Literature}",
79
+ year = "2023",
80
+ url = "https://arxiv.org/abs/2308.12008",
81
+ note = "to appear",
82
+ publisher = "Association for Computational Linguistics",
83
+ booktitle = "Proceedings of the First Workshop on Ancient Language Processing",
84
+ address = "Varna, Bulgaria"
85
+ }
86
+
87
+ ```
config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "bowphs/PhilBerta",
3
+ "architectures": [
4
+ "RobertaModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "bos_token_id": 0,
8
+ "classifier_dropout": null,
9
+ "eos_token_id": 2,
10
+ "hidden_act": "gelu",
11
+ "hidden_dropout_prob": 0.1,
12
+ "hidden_size": 768,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 3072,
15
+ "layer_norm_eps": 1e-05,
16
+ "max_position_embeddings": 514,
17
+ "model_type": "roberta",
18
+ "num_attention_heads": 12,
19
+ "num_hidden_layers": 12,
20
+ "pad_token_id": 1,
21
+ "position_embedding_type": "absolute",
22
+ "torch_dtype": "float32",
23
+ "transformers_version": "4.30.2",
24
+ "type_vocab_size": 1,
25
+ "use_cache": true,
26
+ "vocab_size": 64000
27
+ }
config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.2.2",
4
+ "transformers": "4.30.2",
5
+ "pytorch": "1.6.0+cu101"
6
+ }
7
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
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:214b1e4c53d787eb6254ea9dbfe47cea89021b3978a1f87a77a343403a36fab9
3
+ size 540851063
sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 128,
3
+ "do_lower_case": false
4
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "bos_token": "<s>",
4
+ "clean_up_tokenization_spaces": true,
5
+ "cls_token": "<s>",
6
+ "eos_token": "</s>",
7
+ "errors": "replace",
8
+ "mask_token": "<mask>",
9
+ "model_max_length": 1000000000000000019884624838656,
10
+ "pad_token": "<pad>",
11
+ "sep_token": "</s>",
12
+ "tokenizer_class": "RobertaTokenizer",
13
+ "trim_offsets": true,
14
+ "unk_token": "<unk>"
15
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff