🤖 This project demonstrates the use of a Masked Language Model (MLM) with BERT for predicting masked tokens in a given text. The model is trained to understand the context of words based on their surrounding words, leading to better language understanding.
The Masked Language Model (MLM) is a training objective used in the BERT model. It involves randomly masking some tokens in a sequence and then predicting those masked tokens. This helps the model understand the context of a word based on its surrounding words, leading to better language understanding.
- Predict masked tokens in a sentence using BERT.
- Display training scores including Average Cosine Similarity, Average Jaccard Similarity, Average Edit Distance, and Precision.
- Provide related works for further exploration.
- Python 3.6 or higher
- pip (Python package installer)
- Git (for cloning the repository)
-
Clone the repository:
git clone https://github.com/Nishant2018/Masked-Language-Model-BERT.git cd bert-mlm-nlp
-
Create and activate a virtual environment (optional but recommended):
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Start the Flask web application:
Before starting the flask app verify the BERT Model path. Before using the model extract from zip then pass that path in your flask code.
-
Start the Flask web application:
export FLASK_APP=app.py export FLASK_ENV=development # This enables debug mode flask run
On Windows, use
set
instead ofexport
:set FLASK_APP=app.py set FLASK_ENV=development flask run
-
Open your web browser and navigate to
http://127.0.0.1:5000
.
- Enter a sentence with
[MASK]
tokens where you want the prediction. - Click on the "Submit" button to get the prediction.
- View the results on the page.
The [MASK] quickly jumped over the [MASK] and ran into the [MASK], startling the [MASK] nearby.
The [MASK] sky was filled with [MASK] as the [MASK] festival began. Children ran around with [MASK] in their hands, while adults enjoyed the [MASK] food and music. The evening [MASK] was a [MASK] display of fireworks that lit up the [MASK] night.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Make your changes.
- Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.