class_docstr: Use Bert to generate words.
  
  Example::
  
      小明喜欢看书 -> 小明喜欢看报纸
docstr: Crete the word we need
  
  :param str sentence: the sentence with [MASK]
  :return: the change sentence
docstr_tok: ["Crete","the","word","we","need",":","param","str","sentence",":","the","sentence","with","[","MASK","]",":","return",":","the","change","sentence"]
code: def create_word(self, sentence):
      r"""
      Crete the word we need
  
      :param str sentence: the sentence with [MASK]
      :return: the change sentence
  
      """
      tokenizer = BertTokenizer.from_pretrained("bert-base-chinese")
      text = "[CLS] " + sentence
      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-chinese")
      model.eval()
      masked_index = tokenized_text.index("[MASK]")
      masked_index1 = masked_index + 1
      # Predict all tokens
      with torch.no_grad():
          predictions = model(tokens_tensor, segments_tensors)
  
      predicted_index = torch.argmax(
          predictions[0][0][masked_index]
      ).item()
      predicted_index1 = torch.argmax(
          predictions[0][0][masked_index1]
      ).item()
      predicted_token = tokenizer.convert_ids_to_tokens(
          [predicted_index]
      )[0]
      predicted_token1 = tokenizer.convert_ids_to_tokens(
          [predicted_index1]
      )[0]
      # Determine whether the generated words meet the requirements
      if (
          len(predicted_token) != 1
          or len(predicted_token1) != 1
          or self.is_word(predicted_token + predicted_token1)
      ):
          return ""
      # Change the generated sentence
      return predicted_token + predicted_token1
  
file_path: textflint/textflint/generation/transformation/CWS/cn_mlm.py
imports: import torch
  from transformers import BertTokenizer, BertForMaskedLM
  from ..transformation import Transformation
  from ....input.component.field.cn_text_field import CnTextField
  from ....common.preprocess.cn_processor import CnProcessor
  from ....common.settings import ORIGIN, MODIFIED_MASK
label_desc: Use image node_id 4 for calling the CnMLM obj's underlying member method code with example usage: obj.create_word(sentence) and returns: unknown, str