Upload 7 files
Browse filesFiles changed (7)
- README_language_classification.mdAdded+130
- config.jsonAdded+25
- model.safetensorsAdded+3
- special_tokens_map.jsonAdded+7
- tokenizer.jsonAdded
- tokenizer_config.jsonAdded+56
- vocab.txtAdded
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130# BERT-Based Language Classification Model
This repository contains a fine-tuned BERT-based model for classifying text into different languages. The model is designed to identify the language of a given sentence and has been trained using the Hugging Face Transformers library. It supports post-training dynamic quantization for optimized performance in deployment environments.
---
## Model Details
- **Model Name:** BERT Base for Language Classification - **Model Architecture:** BERT Base - **Task:** Language Identification - **Dataset:** Custom Dataset with multilingual text samples - **Quantization:** Dynamic Quantization (INT8) - **Fine-tuning Framework:** Hugging Face Transformers
---
## Usage
### Installation
```bashpip install transformers torch```
### Loading the Fine-tuned Model
```pythonfrom transformers import pipeline
# Load the model and tokenizer from saved directoryclassifier = pipeline("text-classification", model="./saved_model", tokenizer="./saved_model")
# Example inputtext = "Bonjour, comment allez-vous?"
# Get predictionprediction = classifier(text)print(f"Prediction: {prediction}")```
---
## Saving and Testing the Model
### Saving
```pythonfrom transformers import AutoModelForSequenceClassification, AutoTokenizer
model_checkpoint = "bert-base-uncased" # or your fine-tuned model pathtokenizer = AutoTokenizer.from_pretrained(model_checkpoint)model = AutoModelForSequenceClassification.from_pretrained(model_checkpoint)
# Save model and tokenizermodel.save_pretrained("./saved_model")tokenizer.save_pretrained("./saved_model")```
### Testing
```pythonfrom transformers import pipeline
classifier = pipeline("text-classification", model="./saved_model", tokenizer="./saved_model")text = "Ceci est un exemple de texte."print(classifier(text))```
---
## Quantization
### Apply Dynamic Quantization
```pythonimport torchfrom transformers import AutoModelForSequenceClassification
model = AutoModelForSequenceClassification.from_pretrained("./saved_model")
# Apply dynamic quantizationquantized_model = torch.quantization.quantize_dynamic( model, {torch.nn.Linear}, dtype=torch.qint8)
# Save quantized modelquantized_model.save_pretrained("./quantized_model")```
### Load and Test Quantized Model
```pythonfrom transformers import AutoTokenizer, pipelinefrom transformers import AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("./saved_model")quantized_model = AutoModelForSequenceClassification.from_pretrained("./quantized_model")
classifier = pipeline("text-classification", model=quantized_model, tokenizer=tokenizer)text = "Hola, ¿cómo estás?"print(classifier(text))```
---
## Repository Structure
```.├── saved_model/ # Fine-tuned Model├── quantized_model/ # Quantized Model├── language-clasification.ipynb ├── README.md # Documentation```
---
## Limitations
- The model performance may vary for low-resource or underrepresented languages in the training dataset. - Quantization may slightly reduce accuracy, but improves inference efficiency.
---
## Contributing
Feel free to submit issues or pull requests to enhance performance, accuracy, or add new language support.
---12345678910111213141516171819202122232425{ "architectures": [ "BertForSequenceClassification" ], "attention_probs_dropout_prob": 0.1, "classifier_dropout": null, "gradient_checkpointing": false, "hidden_act": "gelu", "hidden_dropout_prob": 0.1, "hidden_size": 768, "initializer_range": 0.02, "intermediate_size": 3072, "layer_norm_eps": 1e-12, "max_position_embeddings": 512, "model_type": "bert", "num_attention_heads": 12, "num_hidden_layers": 12, "pad_token_id": 0, "position_embedding_type": "absolute", "torch_dtype": "float16", "transformers_version": "4.51.3", "type_vocab_size": 2, "use_cache": true, "vocab_size": 30522}123version https://git-lfs.github.com/spec/v1oid sha256:2482cf07a839e4f091ada914e740ad10849999df90e38f157b86d5d0c8a710dasize 2189909721234567{ "cls_token": "[CLS]", "mask_token": "[MASK]", "pad_token": "[PAD]", "sep_token": "[SEP]", "unk_token": "[UNK]"}1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556{ "added_tokens_decoder": { "0": { "content": "[PAD]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "100": { "content": "[UNK]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "101": { "content": "[CLS]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "102": { "content": "[SEP]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true }, "103": { "content": "[MASK]", "lstrip": false, "normalized": false, "rstrip": false, "single_word": false, "special": true } }, "clean_up_tokenization_spaces": false, "cls_token": "[CLS]", "do_lower_case": true, "extra_special_tokens": {}, "mask_token": "[MASK]", "model_max_length": 512, "pad_token": "[PAD]", "sep_token": "[SEP]", "strip_accents": null, "tokenize_chinese_chars": true, "tokenizer_class": "BertTokenizer", "unk_token": "[UNK]"}README_language_classification.mdAdded+130
config.jsonAdded+25
model.safetensorsAdded+3
special_tokens_map.jsonAdded+7
tokenizer.jsonAdded
tokenizer_config.jsonAdded+56
vocab.txtAdded