Skip to content

Instantly share code, notes, and snippets.

@gaphex
Last active June 9, 2019 11:08
Show Gist options
  • Select an option

  • Save gaphex/1eb3601694d31309c14001e0ddbe3e4c to your computer and use it in GitHub Desktop.

Select an option

Save gaphex/1eb3601694d31309c14001e0ddbe3e4c to your computer and use it in GitHub Desktop.
List of strings to feed dict converter
INPUT_NAMES = ['input_ids', 'input_mask', 'input_type_ids']
bert_tokenizer = FullTokenizer(VOCAB_PATH)
def build_feed_dict(texts):
text_features = list(convert_lst_to_features(
texts, SEQ_LEN, SEQ_LEN,
bert_tokenizer, log, False, False))
target_shape = (len(texts), -1)
feed_dict = {}
for iname in INPUT_NAMES:
features_i = np.array([getattr(f, iname) for f in text_features])
features_i = features_i.reshape(target_shape)
features_i = features_i.astype("int32")
feed_dict[iname] = features_i
return feed_dict
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment