Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Language Classifier

This project trains and runs a simple text classifier that predicts the language of a sentence using a TF-IDF vectorizer and a small PyTorch neural network.

Project Files

  • Language Predicor Model.py - interactive inference script that predicts the language of user input
  • Practice_1.py - training script used to fit the vectorizer, train the model, and save artifacts
  • train.csv - dataset with text and labels columns
  • Saved_model/ - saved model artifacts used by the inference script

Supported Languages

The model maps these label codes to full language names:

Arabic, Bulgarian, German, Greek, English, Spanish, French, Hindi, Italian, Japanese, Dutch, Polish, Portuguese, Russian, Swahili, Thai, Turkish, Urdu, Vietnamese, and Chinese.

Requirements

  • Python 3.9 or newer
  • PyTorch
  • pandas
  • scikit-learn

You can install the Python dependencies with:

pip install torch pandas scikit-learn

Run Inference

The inference script loads the vectorizer, label encoder, and model weights from Saved_model/ and then opens an input loop:

python "Language Predicor Model.py"

Type a sentence and press Enter to get a prediction. Type exit to quit.

Train the Model

To retrain the model:

python Practice_1.py

The training script uses the first 20,000 rows of train.csv for training and the next 5,000 rows for evaluation.

Saved Artifacts

The inference script expects these files inside Saved_model/:

  • tfidf_vectorizer.pkl
  • label_encoder.pkl
  • language_prediction_model_weights.pth

If you retrain the model, make sure the newly generated artifacts are placed in Saved_model/ so the inference script can find them.

Notes

  • The main script filename contains a typo in its current name: Language Predicor Model.py.
  • Accuracy will depend on the contents and quality of train.csv.

Releases

Packages

Contributors

Languages