Last active
June 9, 2019 11:08
-
-
Save gaphex/1eb3601694d31309c14001e0ddbe3e4c to your computer and use it in GitHub Desktop.
List of strings to feed dict converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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