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.
Language Predicor Model.py- interactive inference script that predicts the language of user inputPractice_1.py- training script used to fit the vectorizer, train the model, and save artifactstrain.csv- dataset withtextandlabelscolumnsSaved_model/- saved model artifacts used by the inference script
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.
- Python 3.9 or newer
- PyTorch
- pandas
- scikit-learn
You can install the Python dependencies with:
pip install torch pandas scikit-learnThe 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.
To retrain the model:
python Practice_1.pyThe training script uses the first 20,000 rows of train.csv for training and the next 5,000 rows for evaluation.
The inference script expects these files inside Saved_model/:
tfidf_vectorizer.pkllabel_encoder.pkllanguage_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.
- 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.