<h1>TL;DR</h1>

<p>Try this out: <a href="https://github.com/huggingface/pytorch-pretrained-BERT" rel="noreferrer">https://github.com/huggingface/pytorch-pretrained-BERT</a></p>

<p>First you have to set it up, properly with </p>

<pre><code>pip install -U pytorch-pretrained-bert
</code></pre>

<p>Then you can use the "masked language model" from the BERT algorithm, e.g. </p>

<pre><code>import torch
from pytorch_pretrained_bert import BertTokenizer, BertModel, BertForMaskedLM

# OPTIONAL: if you want to have more information on what's happening, activate the logger as follows
import logging
logging.basicConfig(level=logging.INFO)

# Load pre-trained model tokenizer (vocabulary)
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')

text = '[CLS] I want to [MASK] the car because it is cheap . [SEP]'
tokenized_text = tokenizer.tokenize(text)
indexed_tokens = tokenizer.convert_tokens_to_ids(tokenized_text)

# Create the segments tensors.
segments_ids = [0] * len(tokenized_text)

# Convert inputs to PyTorch tensors
tokens_tensor = torch.tensor([indexed_tokens])
segments_tensors = torch.tensor([segments_ids])

# Load pre-trained model (weights)
model = BertForMaskedLM.from_pretrained('bert-base-uncased')
model.eval()

# Predict all tokens
with torch.no_grad():
    predictions = model(tokens_tensor, segments_tensors)

predicted_index = torch.argmax(predictions[0, masked_index]).item()
predicted_token = tokenizer.convert_ids_to_tokens([predicted_index])[0]

print(predicted_token)
</code></pre>

<p>[out]:</p>

<pre><code>buy
</code></pre>

<h1>In Long</h1>

<p>To truly understand why you need the <code>[CLS]</code>, <code>[MASK]</code> and segment tensors, please do read the paper carefully, <a href="https://arxiv.org/abs/1810.04805" rel="noreferrer">https://arxiv.org/abs/1810.04805</a> </p>

<p>And if you're lazy, you can read this nice blogpost from Lilian Weng, <a href="https://lilianweng.github.io/lil-log/2019/01/31/generalized-language-models.html" rel="noreferrer">https://lilianweng.github.io/lil-log/2019/01/31/generalized-language-models.html</a></p>

<p>Other than BERT, there are a lot of other models that can perform the task of filling in the blank. Do look at the other models in the <code>pytorch-pretrained-BERT</code> repository, but more importantly dive deeper into the task of "Language Modeling", i.e. the task of predicting the next word given a history. </p>
Predicting Missing Words in a sentence - Natural Language Processing Model
<p>I have the sentence below :</p>

<pre><code>I want to ____ the car because it is cheap.
</code></pre>

<p>I want to predict the missing word ,using an NLP model. What NLP model shall I use? Thanks.</p>