(word, word2idx)
return unknown_idx
Get the word index for the given word. Maps all numbers to 0, lowercases if necessary.

    :param word: the word in question
    :param word2idx: dictionary constructed from an embeddings file
    :return: integer index of the word
Get the word index for the given word. Maps all numbers to 0, lowercases if necessary.
Get the word index for the given word . Maps all numbers to 0 lowercases if necessary .
def get_idx(word, word2idx):
    """
    Get the word index for the given word. Maps all numbers to 0, lowercases if necessary.

    :param word: the word in question
    :param word2idx: dictionary constructed from an embeddings file
    :return: integer index of the word
    """
    unknown_idx = word2idx[unknown_el]
    word = word.strip()
    if word in word2idx:
        return word2idx[word]
    elif word.lower() in word2idx:
        return word2idx[word.lower()]
    elif word in special_tokens:
        return word2idx.get(special_tokens[word], unknown_idx)
    trimmed = re.sub("(^\W|\W$)", "", word)
    if trimmed in word2idx:
        return word2idx[trimmed]
    elif trimmed.lower() in word2idx:
        return word2idx[trimmed.lower()]
    no_digits = re.sub("([0-9][0-9.,]*)", '0', word)
    if no_digits in word2idx:
        return word2idx[no_digits]
    return unknown_idx
def get_idx ( word , word2idx ) : unknown_idx = word2idx [ unknown_el ] word = word . strip ( ) if word in word2idx : return word2idx [ word ] elif word . lower ( ) in word2idx : return word2idx [ word . lower ( ) ] elif word in special_tokens : return word2idx . get ( special_tokens [ word ] , unknown_idx ) trimmed = re . sub ( "(^\W|\W$)" , "" , word ) if trimmed in word2idx : return word2idx [ trimmed ] elif trimmed . lower ( ) in word2idx : return word2idx [ trimmed . lower ( ) ] no_digits = re . sub ( "([0-9][0-9.,]*)" , '0' , word ) if no_digits in word2idx : return word2idx [ no_digits ] return unknown_idx