transformers-rb 0.1.1 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/README.md +64 -3
- data/lib/transformers/configuration_utils.rb +32 -4
- data/lib/transformers/modeling_utils.rb +10 -3
- data/lib/transformers/models/auto/auto_factory.rb +1 -1
- data/lib/transformers/models/auto/configuration_auto.rb +5 -2
- data/lib/transformers/models/auto/modeling_auto.rb +9 -3
- data/lib/transformers/models/auto/tokenization_auto.rb +5 -2
- data/lib/transformers/models/deberta_v2/configuration_deberta_v2.rb +80 -0
- data/lib/transformers/models/deberta_v2/modeling_deberta_v2.rb +1210 -0
- data/lib/transformers/models/deberta_v2/tokenization_deberta_v2_fast.rb +78 -0
- data/lib/transformers/models/mpnet/configuration_mpnet.rb +61 -0
- data/lib/transformers/models/mpnet/modeling_mpnet.rb +792 -0
- data/lib/transformers/models/mpnet/tokenization_mpnet_fast.rb +106 -0
- data/lib/transformers/models/xlm_roberta/configuration_xlm_roberta.rb +68 -0
- data/lib/transformers/models/xlm_roberta/modeling_xlm_roberta.rb +1216 -0
- data/lib/transformers/models/xlm_roberta/tokenization_xlm_roberta_fast.rb +68 -0
- data/lib/transformers/pipelines/_init.rb +16 -5
- data/lib/transformers/pipelines/reranking.rb +33 -0
- data/lib/transformers/version.rb +1 -1
- data/lib/transformers.rb +16 -0
- metadata +15 -5
@@ -0,0 +1,78 @@
|
|
1
|
+
# Copyright 2020 Microsoft and the HuggingFace Inc. team.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
module Transformers
|
16
|
+
module DebertaV2
|
17
|
+
class DebertaV2TokenizerFast < PreTrainedTokenizerFast
|
18
|
+
VOCAB_FILES_NAMES = {vocab_file: "spm.model", tokenizer_file: "tokenizer.json"}
|
19
|
+
|
20
|
+
self.vocab_files_names = VOCAB_FILES_NAMES
|
21
|
+
# self.slow_tokenizer_class = DebertaV2Tokenizer
|
22
|
+
|
23
|
+
def initialize(
|
24
|
+
vocab_file: nil,
|
25
|
+
tokenizer_file: nil,
|
26
|
+
do_lower_case: false,
|
27
|
+
split_by_punct: false,
|
28
|
+
bos_token: "[CLS]",
|
29
|
+
eos_token: "[SEP]",
|
30
|
+
unk_token: "[UNK]",
|
31
|
+
sep_token: "[SEP]",
|
32
|
+
pad_token: "[PAD]",
|
33
|
+
cls_token: "[CLS]",
|
34
|
+
mask_token: "[MASK]",
|
35
|
+
**kwargs
|
36
|
+
)
|
37
|
+
super(vocab_file, tokenizer_file: tokenizer_file, do_lower_case: do_lower_case, bos_token: bos_token, eos_token: eos_token, unk_token: unk_token, sep_token: sep_token, pad_token: pad_token, cls_token: cls_token, mask_token: mask_token, split_by_punct: split_by_punct, **kwargs)
|
38
|
+
|
39
|
+
@do_lower_case = do_lower_case
|
40
|
+
@split_by_punct = split_by_punct
|
41
|
+
@vocab_file = vocab_file
|
42
|
+
end
|
43
|
+
|
44
|
+
def can_save_slow_tokenizer
|
45
|
+
@vocab_file ? File.exist?(@vocab_file) : false
|
46
|
+
end
|
47
|
+
|
48
|
+
def build_inputs_with_special_tokens(token_ids_0, token_ids_1: nil)
|
49
|
+
if token_ids_1.nil?
|
50
|
+
return [@cls_token_id] + token_ids_0 + [@sep_token_id]
|
51
|
+
end
|
52
|
+
cls = [@cls_token_id]
|
53
|
+
sep = [@sep_token_id]
|
54
|
+
cls + token_ids_0 + sep + token_ids_1 + sep
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_special_tokens_mask(token_ids_0, token_ids_1: nil, already_has_special_tokens: false)
|
58
|
+
if already_has_special_tokens
|
59
|
+
return super(token_ids_0: token_ids_0, token_ids_1: token_ids_1, already_has_special_tokens: true)
|
60
|
+
end
|
61
|
+
|
62
|
+
if !token_ids_1.nil?
|
63
|
+
return [1] + ([0] * token_ids_0.length) + [1] + ([0] * token_ids_1.length) + [1]
|
64
|
+
end
|
65
|
+
[1] + ([0] * token_ids_0.length) + [1]
|
66
|
+
end
|
67
|
+
|
68
|
+
def create_token_type_ids_from_sequences(token_ids_0, token_ids_1: nil)
|
69
|
+
sep = [@sep_token_id]
|
70
|
+
cls = [@cls_token_id]
|
71
|
+
if token_ids_1.nil?
|
72
|
+
return (cls + token_ids_0 + sep).length * [0]
|
73
|
+
end
|
74
|
+
((cls + token_ids_0 + sep).length * [0]) + ((token_ids_1 + sep).length * [1])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright 2018 The HuggingFace Inc. team, Microsoft Corporation.
|
2
|
+
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
module Transformers
|
17
|
+
module Mpnet
|
18
|
+
class MPNetConfig < PretrainedConfig
|
19
|
+
self.model_type = "mpnet"
|
20
|
+
|
21
|
+
attr_reader :vocab_size, :hidden_size, :num_hidden_layers, :num_attention_heads,
|
22
|
+
:intermediate_size, :hidden_act, :hidden_dropout_prob, :attention_probs_dropout_prob,
|
23
|
+
:max_position_embeddings, :initializer_range, :layer_norm_eps, :relative_attention_num_buckets,
|
24
|
+
:pad_token_id, :bos_token_id, :eos_token_id
|
25
|
+
|
26
|
+
def initialize(
|
27
|
+
vocab_size: 30527,
|
28
|
+
hidden_size: 768,
|
29
|
+
num_hidden_layers: 12,
|
30
|
+
num_attention_heads: 12,
|
31
|
+
intermediate_size: 3072,
|
32
|
+
hidden_act: "gelu",
|
33
|
+
hidden_dropout_prob: 0.1,
|
34
|
+
attention_probs_dropout_prob: 0.1,
|
35
|
+
max_position_embeddings: 512,
|
36
|
+
initializer_range: 0.02,
|
37
|
+
layer_norm_eps: 1e-12,
|
38
|
+
relative_attention_num_buckets: 32,
|
39
|
+
pad_token_id: 1,
|
40
|
+
bos_token_id: 0,
|
41
|
+
eos_token_id: 2,
|
42
|
+
**kwargs
|
43
|
+
)
|
44
|
+
super(pad_token_id: pad_token_id, bos_token_id: bos_token_id, eos_token_id: eos_token_id, **kwargs)
|
45
|
+
|
46
|
+
@vocab_size = vocab_size
|
47
|
+
@hidden_size = hidden_size
|
48
|
+
@num_hidden_layers = num_hidden_layers
|
49
|
+
@num_attention_heads = num_attention_heads
|
50
|
+
@hidden_act = hidden_act
|
51
|
+
@intermediate_size = intermediate_size
|
52
|
+
@hidden_dropout_prob = hidden_dropout_prob
|
53
|
+
@attention_probs_dropout_prob = attention_probs_dropout_prob
|
54
|
+
@max_position_embeddings = max_position_embeddings
|
55
|
+
@initializer_range = initializer_range
|
56
|
+
@layer_norm_eps = layer_norm_eps
|
57
|
+
@relative_attention_num_buckets = relative_attention_num_buckets
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|