Last active
March 18, 2018 18:03
-
-
Save anna-hope/9d3cb9284d8d5667857baeb46b4880fa to your computer and use it in GitHub Desktop.
Make torchtext training examples from pandas.DataFrame on the fly
This file contains 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
import pandas as pd | |
from torchtext import data | |
from tqdm import tqdm | |
def make_examples(df: pd.DataFrame, fields: Dict[str, data.Field]): | |
fields = {field_name: (field_name, field) | |
for field_name, field in fields.items()} | |
for _, row in tqdm(df.iterrows()): | |
example = data.Example.fromdict(row, fields) | |
yield example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment