Python transformers.RobertaConfig() Examples
The following are 7
code examples of transformers.RobertaConfig().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
transformers
, or try the search function
.
Example #1
Source File: config.py From unilm with MIT License | 5 votes |
def from_exist_config(cls, config, label_smoothing=0.1, max_position_embeddings=None): required_keys = [ "vocab_size", "hidden_size", "num_hidden_layers", "num_attention_heads", "hidden_act", "intermediate_size", "hidden_dropout_prob", "attention_probs_dropout_prob", "max_position_embeddings", "type_vocab_size", "initializer_range", "layer_norm_eps"] kwargs = {} for key in required_keys: assert hasattr(config, key) kwargs[key] = getattr(config, key) kwargs["vocab_size_or_config_json_file"] = kwargs["vocab_size"] if isinstance(config, RobertaConfig): kwargs["type_vocab_size"] = 0 kwargs["max_position_embeddings"] = kwargs["max_position_embeddings"] - 2 additional_keys = [ "source_type_id", "target_type_id" ] for key in additional_keys: if hasattr(config, key): kwargs[key] = getattr(config, key) if max_position_embeddings is not None and max_position_embeddings > config.max_position_embeddings: kwargs["max_position_embeddings"] = max_position_embeddings logger.info(" ** Change max position embeddings to %d ** " % max_position_embeddings) return cls(label_smoothing=label_smoothing, **kwargs)
Example #2
Source File: test_modeling_tf_roberta.py From exbert with Apache License 2.0 | 5 votes |
def prepare_config_and_inputs(self): input_ids = ids_tensor([self.batch_size, self.seq_length], self.vocab_size) input_mask = None if self.use_input_mask: input_mask = ids_tensor([self.batch_size, self.seq_length], vocab_size=2) token_type_ids = None if self.use_token_type_ids: token_type_ids = ids_tensor([self.batch_size, self.seq_length], self.type_vocab_size) sequence_labels = None token_labels = None choice_labels = None if self.use_labels: sequence_labels = ids_tensor([self.batch_size], self.type_sequence_label_size) token_labels = ids_tensor([self.batch_size, self.seq_length], self.num_labels) choice_labels = ids_tensor([self.batch_size], self.num_choices) config = RobertaConfig( vocab_size=self.vocab_size, hidden_size=self.hidden_size, num_hidden_layers=self.num_hidden_layers, num_attention_heads=self.num_attention_heads, intermediate_size=self.intermediate_size, hidden_act=self.hidden_act, hidden_dropout_prob=self.hidden_dropout_prob, attention_probs_dropout_prob=self.attention_probs_dropout_prob, max_position_embeddings=self.max_position_embeddings, type_vocab_size=self.type_vocab_size, initializer_range=self.initializer_range, ) return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels
Example #3
Source File: test_modeling_tf_roberta.py From exbert with Apache License 2.0 | 5 votes |
def setUp(self): self.model_tester = TFRobertaModelTest.TFRobertaModelTester(self) self.config_tester = ConfigTester(self, config_class=RobertaConfig, hidden_size=37)
Example #4
Source File: test_transformers.py From keras-onnx with MIT License | 5 votes |
def test_TFRobertaModel(self): from transformers import RobertaConfig, TFRobertaModel keras.backend.clear_session() # pretrained_weights = 'roberta-base' tokenizer_file = 'roberta_roberta-base.pickle' tokenizer = self._get_tokenzier(tokenizer_file) text, inputs, inputs_onnx = self._prepare_inputs(tokenizer) config = RobertaConfig() model = TFRobertaModel(config) predictions = model.predict(inputs) onnx_model = keras2onnx.convert_keras(model, model.name) self.assertTrue(run_onnx_runtime(onnx_model.graph.name, onnx_model, inputs_onnx, predictions, self.model_files))
Example #5
Source File: test_transformers.py From keras-onnx with MIT License | 5 votes |
def test_TFRobertaForMaskedLM(self): from transformers import RobertaConfig, TFRobertaForMaskedLM keras.backend.clear_session() # pretrained_weights = 'roberta-base' tokenizer_file = 'roberta_roberta-base.pickle' tokenizer = self._get_tokenzier(tokenizer_file) text, inputs, inputs_onnx = self._prepare_inputs(tokenizer) config = RobertaConfig() model = TFRobertaForMaskedLM(config) predictions = model.predict(inputs) onnx_model = keras2onnx.convert_keras(model, model.name) self.assertTrue( run_onnx_runtime(onnx_model.graph.name, onnx_model, inputs_onnx, predictions, self.model_files, rtol=1.e-2, atol=1.e-4))
Example #6
Source File: test_transformers.py From keras-onnx with MIT License | 5 votes |
def test_TFRobertaForSequenceClassification(self): from transformers import RobertaConfig, TFRobertaForSequenceClassification keras.backend.clear_session() # pretrained_weights = 'roberta-base' tokenizer_file = 'roberta_roberta-base.pickle' tokenizer = self._get_tokenzier(tokenizer_file) text, inputs, inputs_onnx = self._prepare_inputs(tokenizer) config = RobertaConfig() model = TFRobertaForSequenceClassification(config) predictions = model.predict(inputs) onnx_model = keras2onnx.convert_keras(model, model.name) self.assertTrue(run_onnx_runtime(onnx_model.graph.name, onnx_model, inputs_onnx, predictions, self.model_files))
Example #7
Source File: test_transformers.py From keras-onnx with MIT License | 5 votes |
def test_TFRobertaForTokenClassification(self): from transformers import RobertaConfig, TFRobertaForTokenClassification keras.backend.clear_session() # pretrained_weights = 'roberta-base' tokenizer_file = 'roberta_roberta-base.pickle' tokenizer = self._get_tokenzier(tokenizer_file) text, inputs, inputs_onnx = self._prepare_inputs(tokenizer) config = RobertaConfig() model = TFRobertaForTokenClassification(config) predictions = model.predict(inputs) onnx_model = keras2onnx.convert_keras(model, model.name) self.assertTrue(run_onnx_runtime(onnx_model.graph.name, onnx_model, inputs_onnx, predictions, self.model_files))