import torch from transformers import BertModel, BertTokenizer import numpy as np import time def get_word_vec(word): # 这里我们调用bert-base模型,同时模型的词典经过小写处理 model_name = 'bert-base-uncased' # 读取模型对应的tokenizer tokenizer = BertTokenizer.from_pretrained(model_name) # 载入模型 model = BertModel.from_pretrained(model_name) # 输入文本 input_text = word # 通过tokenizer把文本变成 token_id input_ids = torch.tensor([tokenizer.encode(input_text_i) for input_text_i in input_text]) max_len = 10 # while len(input_ids)