Unrecognized configuration class <class 'transformers.models.bert.configuration_bert.BertConfig'> for this kind of AutoModel: AutoModelForSeq2SeqLM - nlp

Model type should be one of BartConfig, PLBartConfig, BigBirdPegasusConfig, M2M100Config, LEDConfig, BlenderbotSmallConfig, MT5Config, T5Config, PegasusConfig, MarianConfig, MBartConfig, BartConfig, BlenderbotConfig, FSMTConfig, XLMProphetNetConfig, ProphetNetConfig, EncoderDecoderConfig.
I am trying to load a fine-tuned Bert model for machine translation using AutoModelForSeq2SeqLM but it can't recognize the configuration class.
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, Seq2SeqTrainingArguments, Seq2SeqTrainer
model = AutoModelForSeq2SeqLM.from_pretrained('/content/drive/MyDrive/Models/CSE498')
Config File
{
"_name_or_path": "ckiplab/albert-tiny-chinese",
"architectures": [
"BertForMaskedLM"
],
"attention_probs_dropout_prob": 0.0,
"bos_token_id": 101,
"classifier_dropout": null,
"classifier_dropout_prob": 0.1,
"down_scale_factor": 1,
"embedding_size": 128,
"eos_token_id": 102,
"gap_size": 0,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.0,
"hidden_size": 312,
"initializer_range": 0.02,
"inner_group_num": 1,
"intermediate_size": 1248,
"layer_norm_eps": 1e-12,
"max_position_embeddings": 512,
"model_type": "bert",
"net_structure_type": 0,
"num_attention_heads": 12,
"num_hidden_groups": 1,
"num_hidden_layers": 4,
"num_memory_blocks": 0,
"pad_token_id": 0,
"position_embedding_type": "absolute",
"tokenizer_class": "BertTokenizerFast",
"torch_dtype": "float32",
"transformers_version": "4.18.0",
"type_vocab_size": 2,
"use_cache": true,
"vocab_size": 30522
}

This is because BERT itself is not a seq2seq model. You can consider using a pre-trained BART instead.

Related

Understanding the config file of paraphrase mpnet base v2?

Here is the config file of the paraphrase mpnet transformer model and I would like to understand the meaning with examples of the hidden_size and num_hidden_layers parameters.
{
"_name_or_path": "old_models/paraphrase-mpnet-base-v2/0_Transformer",
"architectures": [
"MPNetModel"
],
"attention_probs_dropout_prob": 0.1,
"bos_token_id": 0,
"eos_token_id": 2,
"hidden_act": "gelu",
"hidden_dropout_prob": 0.1,
"hidden_size": 768,
"initializer_range": 0.02,
"intermediate_size": 3072,
"layer_norm_eps": 1e-05,
"max_position_embeddings": 514,
"model_type": "mpnet",
"num_attention_heads": 12,
"num_hidden_layers": 12,
"pad_token_id": 1,
"relative_attention_num_buckets": 32,
"transformers_version": "4.7.0",
"vocab_size": 30527
}

When training jukebox on notebooks, why is our training data is stuck at 0 for Sample length and min duration?

Hps data:
/home/dotty/anaconda3/envs/JukVersionRoy/jukebox/train.py --hps=small_vqvae --name=small_vqvae --sample_length=9999999999999 --bs=2 --audio_files_dir=/home/dotty/anaconda3/envs/JukVersionRoy/jukebox/my-training-data --labels=False --train --aug_shift --aug_blend
Here
/
HPS ***************
{'rcall_command': '<unknown_rcall_command>', 'git_commit': '<unknown_git_commit>', 'name': '', 'debug_mem': False, 'debug_eval_files': False, 'debug_speed': False, 'debug_iters': 100, 'debug_batch': False, 'debug_grad_accum': False, 'debug_inputs': False, 'local_path': '', 'local_logdir': 'logs', 'max_len': 24, 'max_log': 32, 'save': True, 'save_iters': 20000, 'seed': 0, 'prior': False, 'log_steps': 100, 'func': '', 'audio_files_dir': '', 'finetune': '', 'english_only': False, 'bs': 1, 'bs_sample': 1, 'nworkers': 1, 'aug_shift': False, 'aug_blend': False, 'train_test_split': 0.9, 'train_shrink_factor': 1.0, 'test_shrink_factor': 1.0, 'p_unk': 0.1, 'min_duration': None, 'max_duration': None, 'n_tokens': 0, 'n_vocab': 0, 'use_tokens': False, 'curr_epoch': -1, 'restore_vqvae': '', 'levels': 2, 'downs_t': (1, 1), 'strides_t': (2, 2), 'hvqvae_multipliers': None, 'revival_threshold': 1.0, 'emb_width': 64, 'l_bins': 512, 'l_mu': 0.99, 'commit': 1.0, 'spectral': 0.0, 'multispectral': 1.0, 'loss_fn': 'l2', 'linf_k': 2048, 'lmix_l1': 0.0, 'lmix_l2': 0.0, 'lmix_linf': 0.0, 'use_bottleneck': True, 'depth': 3, 'width': 128, 'm_conv': 1.0, 'dilation_growth_rate': 1, 'dilation_cycle': None, 'vqvae_reverse_decoder_dilation': True, 'restore_prior': '', 'restore_prior_ddp': False, 'max_bow_genre_size': None, 'y_bins': 0, 'level': 0, 'cond_levels': None, 't_bins': 64, 'y_cond_as_bias': False, 'copy_input': False, 'merged_decoder': False, 'single_enc_dec': False, 'alignment_layer': None, 'alignment_head': None, 'n_ctx': 1024, 'prior_depth': 3, 'prior_width': 128, 'heads': 1, 'attn_order': 0, 'blocks': None, 'spread': None, 'attn_dropout': 0.0, 'resid_dropout': 0.0, 'emb_dropout': 0.0, 'zero_out': False, 'res_scale': False, 'pos_init': False, 'init_scale': 1.0, 'm_attn': 0.25, 'm_mlp': 1.0, 'c_res': 0, 'c_attn': 0, 'c_mlp': 0, 'cond_depth': 3, 'cond_width': 128, 'cond_m_conv': 1.0, 'cond_zero_out': False, 'cond_res_scale': False, 'cond_dilation_growth_rate': 1, 'cond_dilation_cycle': None, 'cond_c_res': 0, 'primed_chunk_size': None, 'selected_artists': '', 'temp_top': 1.0, 'temp_rest': 0.99, 'sample_length_in_seconds': 24, 'total_sample_length_in_seconds': 240, 'prime_loss_fraction': 0.1, 'restore_decoder': '', 'prime_depth': 3, 'prime_width': 128, 'prime_heads': 1, 'prime_attn_order': 0, 'prime_blocks': None, 'prime_spread': None, 'prime_attn_dropout': 0.0, 'prime_resid_dropout': 0.0, 'prime_emb_dropout': 0.0, 'prime_zero_out': False, 'prime_res_scale': False, 'prime_pos_init': False, 'prime_init_scale': 1.0, 'prime_m_attn': 0.25, 'prime_m_mlp': 1.0, 'prime_c_res': 0, 'prime_c_attn': 0, 'prime_c_mlp': 0, 'prime_rel_attn': False, 'prime_posemb_timescale': 10000, 'epochs': 10000, 'lr': 0.0003, 'clip': 1.0, 'beta1': 0.9, 'beta2': 0.999, 'ignore_grad_norm': 0, 'weight_decay': 0.0, 'eps': 1e-08, 'lr_warmup': 100.0, 'lr_decay': 10000000000.0, 'lr_gamma': 1.0, 'lr_scale': 1.0, 'lr_use_linear_decay': False, 'lr_start_linear_decay': 0, 'lr_use_cosine_decay': False, 'fp16': False, 'fp16_params': False, 'fp16_loss_scale': None, 'fp16_scale_window': 1000.0, 'fp16_opt': False, 'labels': True, 'labels_v3': False, 'dump': False, 'ema': True, 'ema_fused': True, 'cpu_ema': False, 'cpu_ema_freq': 100, 'reset_best_loss': False, 'reset_step': False, 'reset_opt': False, 'reset_shd': False, 'train': False, 'test': False, 'sample': False, 'sampler': 'ancestral', 'codes_logdir': '', 'date': None, 'labeller': 'top_genres', 'label_line': 0, 'iters_before_update': 1, 'grad_accum_iters': 0, 'mu': None, 'piped': False, 'pipe_depth': 8, 'break_train': 10000000000.0, 'break_test': 10000000000.0, 'exit_train': 10000000000.0, 'n_fft': 1024, 'hop_length': 256, 'window_size': 1024, 'sr': 44100, 'channels': 2, 'wav': '', 'n_inps': 1, 'n_hops': 2, 'n_segment': 1, 'n_total_segment': 1, 'n_segment_each': 1, 'prime_chunks': 4, 'sample_length': 0, 'sample_hop_length': 30000, 'max_silence_pad_length': 0, 'ignore_boundaries': False, 'use_nonrelative_specloss': True, 'multispec_loss_n_fft': (2048, 1024, 512), 'multispec_loss_hop_length': (240, 120, 50), 'multispec_loss_window_size': (1200, 600, 240), 'bucket': 128, 'ngpus': 16, 'argv': '/home/dotty/anaconda3/envs/JukVersionRoy/jukebox/train.py --hps=small_vqvae --name=small_vqvae --sample_length=9999999999999 --bs=2 --audio_files_dir=/home/dotty/anaconda3/envs/JukVersionRoy/jukebox/my-training-data --labels=False --train --aug_shift --aug_blend'}
SAMPLE LENGTH:
0
SAMPLE RATE:
44100
SAMPLE LENGTH / SAMPLE RATE:
0.0
MIN DURATION:
0
AssertionError Traceback (most recent call last)
/tmp/ipykernel_14312/1841762803.py in <module>
325
326
--> 327 run()
/tmp/ipykernel_14312/1841762803.py in run(hps, port, **kwargs)
283 print("HPS ***************")
284 print(hps)
--> 285 data_processor = DataProcessor(hps)
286
287 # Setup models
~/anaconda3/envs/JukVersionRoy/jukebox/data/data_processor.py in init(self, hps)
24 class DataProcessor():
25 def init(self, hps):
---> 26 self.dataset = FilesAudioDataset(hps)
27 duration = 1 if hps.prior else 600
28 hps.bandwidth = calculate_bandwidth(self.dataset, hps, duration=duration)
~/anaconda3/envs/JukVersionRoy/jukebox/data/files_dataset.py in init(self, hps)
24 print("MIN DURATION:")
25 print(self.min_duration)
---> 26 assert hps.sample_length / hps.sr < self.min_duration, f'Sample length {hps.sample_length} per sr {hps.sr} ({hps.sample_length / hps.sr:.2f}) should be shorter than min duration {self.min_duration}'
27 self.aug_shift = hps.aug_shift
28 self.labels = hps.labels
AssertionError: Sample length 0 per sr 44100 (0.00) should be shorter than min duration 0
Our files are not being read in, as the sample stayed at 44100 when we changed the files being read in. we went through all the files dataset.py, dataprocessor.py and audio_utils.py and could not finds where exactly the input files is being registered. Our path is correct. We are trying to sample length and min duration to be read in correctly.

How to read predict() result in Tensorflowjs using a SavedModel

Code using tfjs-node:
const model = await tf.node.loadSavedModel(modelPath);
const data = fs.readFileSync(imgPath);
const tfimage = tf.node.decodeImage(data, 3);
const expanded = tfimage.expandDims(0);
const result = model.predict(expanded);
console.log(result);
for (r of result) {
console.log(r.dataSync());
}
Output:
(8) [Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor, Tensor]
Float32Array(100) [48700, 48563, 48779, 48779, 49041, 48779, ...]
Float32Array(400) [0.10901492834091187, 0.18931034207344055, 0.9181075692176819, 0.8344497084617615, ...]
Float32Array(100) [61, 88, 65, 84, 67, 51, 62, 20, 59, 9, 18, ...]
Float32Array(9000) [0.009332209825515747, 0.003941178321838379, 0.0005068182945251465, 0.001926332712173462, 0.0020033419132232666, 0.000742495059967041, 0.022082984447479248, 0.0032682716846466064, 0.05071520805358887, 0.000018596649169921875, ...]
Float32Array(100) [0.6730095148086548, 0.1356855034828186, 0.12674063444137573, 0.12360832095146179, 0.10837388038635254, 0.10075071454048157, ...]
Float32Array(1) [100]
Float32Array(196416) [0.738592267036438, 0.4373246729373932, 0.738592267036438, 0.546840488910675, -0.010780575685203075, 0.00041256844997406006, 0.03478313609957695, 0.11279871314764023, -0.0504981130361557, -0.11237315833568573, 0.02907072752714157, 0.06638012826442719, 0.001794634386897087, 0.0009463857859373093, ...]
Float32Array(4419360) [0.0564018189907074, 0.016801774501800537, 0.025803595781326294, 0.011671125888824463, 0.014013528823852539, 0.008442580699920654, ...]
How do I read the predict() response for object detection? I was expecting a dictionary with num_detections, detection_boxes, detection_classes, etc. as described here.
I also tried using tf.execute(), but it throws me the following error: UnhandledPromiseRejectionWarning: Error: execute() of TFSavedModel is not supported yet.
I'm using efficientdet/d0 downloaded from here.
When you download the tensor using dataSync() it just keeps the value. If you wanted the object with a description of each of the results without the tensors you would just have to console.log(result). Then you expand the result from your log in the browsers console it should return something like this:
Tensor {
"dataId": Object {},
"dtype": "float32",
"id": 160213,
"isDisposedInternal": false,
"kept": false,
"rankType": "2",
"scopeId": 365032,
"shape": Array [
1,
3,
],
"size": 3,
"strides": Array [
3,
],
}
The output of your console.log(result) contains 8 tensors within it which shows that it is correct. You are looping over each of the results and each of the outputs should follow this format :
['num_detections', 'detection_boxes', 'detection_classes', 'detection_scores', 'raw_detection_boxes', 'raw_detection_scores, 'detection_anchor_indices', 'detection_multiclass_scores']

HuggingFace - GPT2 Tokenizer configuration in config.json

The GPT2 finetuned model is uploaded in huggingface-models for the inferencing
Below error is observed during the inference,
Can't load tokenizer using from_pretrained, please update its configuration: Can't load tokenizer for 'bala1802/model_1_test'. Make sure that: - 'bala1802/model_1_test' is a correct model identifier listed on 'https://huggingface.co/models' - or 'bala1802/model_1_test' is the correct path to a directory containing relevant tokenizer files
Below is the configuration - config.json file for the Finetuned huggingface model,
{
"_name_or_path": "gpt2",
"activation_function": "gelu_new",
"architectures": [
"GPT2LMHeadModel"
],
"attn_pdrop": 0.1,
"bos_token_id": 50256,
"embd_pdrop": 0.1,
"eos_token_id": 50256,
"gradient_checkpointing": false,
"initializer_range": 0.02,
"layer_norm_epsilon": 1e-05,
"model_type": "gpt2",
"n_ctx": 1024,
"n_embd": 768,
"n_head": 12,
"n_inner": null,
"n_layer": 12,
"n_positions": 1024,
"resid_pdrop": 0.1,
"summary_activation": null,
"summary_first_dropout": 0.1,
"summary_proj_to_labels": true,
"summary_type": "cls_index",
"summary_use_proj": true,
"task_specific_params": {
"text-generation": {
"do_sample": true,
"max_length": 50
}
},
"transformers_version": "4.3.2",
"use_cache": true,
"vocab_size": 50257
}
Should I configure the GPT2 Tokenizer just like the "model_type": "gpt2" in the config.json file
Your repository does not contain the required files to create a tokenizer. It seems like you have only uploaded the files for your model. Create an object of your tokenizer that you have used for training the model and save the required files with save_pretrained():
from transformers import GPT2Tokenizer
t = GPT2Tokenizer.from_pretrained("gpt2")
t.save_pretrained('/SOMEFOLDER/')
Output:
('/SOMEFOLDER/tokenizer_config.json',
'/SOMEFOLDER/special_tokens_map.json',
'/SOMEFOLDER/vocab.json',
'/SOMEFOLDER/merges.txt',
'/SOMEFOLDER/added_tokens.json')

pass array of arrays from routes to view node.js

I am trying to pass an array of arrays from routes to view page. My data that I am trying to pass is :
[
[10, 10],
[20, 50],
[30, 120],
[40, 80],
[50, 90],
[60, 50],
[70, 70],
[80, 90],
[90, 150],
[100, 50],
[110, 40],
[120, 70],
[130, 20],
[140, 40],
[200, 30]
]
I am getting it in below format:
["10,10,20,50,30,120,40,80,50,90,60,50,70,70,80,90,90,150,100,50,110,40,120,70,130,20,140,40,200,30"]
but I need it in the same format I am sending.
My index.js(routes file) is:
router.get('/', function(req, res, next) {
var dataset = [
[10, 10],
[20, 50],
[30, 120],
[40, 80],
[50, 90],
[60, 50],
[70, 70],
[80, 90],
[90, 150],
[100, 50],
[110, 40],
[120, 70],
[130, 20],
[140, 40],
[200, 30]
];
console.log(dataset);
res.render('index',{"data" : [dataset]});
});
module.exports = router;
and in my view file, I am trying to get it like:
<div class="hold_data" data-info={{data}}></div>
Please suggest if anyone knows how this can be achieved. Thanks in advance :)
Try JSON.stringify as below -
res.render('index',{"data" : JSON.stringify(dataset)});
Hope this helps.

Resources