examples/language_model/end_to_end_memory_networks/data.py
def read_data(fname, word2idx):
    """
    Data is processed into a one-dimensional vector, and each value is the code corresponding to a word.
    The two sentences are separated by special characters < EOS >.
    
    Args:
        fname (str):
            data filename
        word2idx (dict):
            word dict
    
    Returns:
        list: return word vectors
    """
    if os.path.isfile(fname):
        with open(fname) as f:
            lines = f.readlines()
    else:
        raise (Exception("[!] Data %s not found" % fname))

    words = []
    for line in lines:
        words.extend(line.split())

    print("Read %s words from %s" % (len(words), fname))

    data = list()
    for line in lines:
        for word in line.split():
            index = word2idx[word]
            data.append(index)
        data.append(word2idx['<eos>'])
    return data

    Data is processed into a one-dimensional vector, and each value is the code corresponding to a word.
    The two sentences are separated by special characters < EOS >.
    
    Args:
        fname (str):
            data filename
        word2idx (dict):
            word dict
    
    Returns:
        list: return word vectors
    
Data is processed into a one-dimensional vector, and each value is the code corresponding to a word.
The two sentences are separated by special characters < EOS >.
Data is processed into a one - dimensional vector and each value is the code corresponding to a word . The two sentences are separated by special characters < EOS > .
def read_data(fname, word2idx):
    if os.path.isfile(fname):
        with open(fname) as f:
            lines = f.readlines()
    else:
        raise (Exception("[!] Data %s not found" % fname))
    words = []
    for line in lines:
        words.extend(line.split())
    print("Read %s words from %s" % (len(words), fname))
    data = list()
    for line in lines:
        for word in line.split():
            index = word2idx[word]
            data.append(index)
        data.append(word2idx['<eos>'])
    return data
def read_data ( fname , word2idx ) : if os . path . isfile ( fname ) : with open ( fname ) as f : lines = f . readlines ( ) else : raise ( Exception ( "[!] Data %s not found" % fname ) ) words = [ ] for line in lines : words . extend ( line . split ( ) ) print ( "Read %s words from %s" % ( len ( words ) , fname ) ) data = list ( ) for line in lines : for word in line . split ( ) : index = word2idx [ word ] data . append ( index ) data . append ( word2idx [ '<eos>' ] ) return data
Data is processed into a one-dimensional vector, and each value is the code corresponding to a word.
Data is processed into a one - dimensional vector and each value is the code corresponding to a word .
"""
    Data is processed into a one-dimensional vector, and each value is the code corresponding to a word.
    The two sentences are separated by special characters < EOS >.
    
    Args:
        fname (str):
            data filename
        word2idx (dict):
            word dict
    
    Returns:
        list: return word vectors
    """
return word vectors
return word vectors
list
fname
None
word2idx
None