text_html_output_1.png text_plain_output_1.png
import numpy as np # linear algebra

import pandas as pd

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import pandas as pd
data = pd.read_csv('../input/twitter-train/train.txt', delimiter='\n', header=None)

data_array = data.to_numpy()
x_array = np.reshape(data_array, (-1, 3))
column = ['Tweet', 'Target', 'Sentiment']
data = pd.DataFrame(data=x_array, columns=column)
data

my_dataset = data
my_dataset = my_dataset.drop(['Target', 'Sentiment'], axis=1)
my_target = data.drop(['Tweet', 'Sentiment'], axis=1)
for i in my_dataset.index:
    x = my_dataset['Tweet'][i].find('$T$')
s = my_dataset['Tweet'][1].replace('$T$', my_target['Target'][0])
j = 0
my_targetless_tweet = []
for i in range(6248):
    my_targetless_tweet.insert(i, my_dataset['Tweet'][i].replace('$T$', my_target['Target'][j]))
    j = j + 1

my_targetless_tweet = pd.DataFrame(my_targetless_tweet)
my_targetless_tweet
targetless_tweet = my_targetless_tweet.to_numpy()
new_array = np.reshape(targetless_tweet, (-1, 1))
column = ['Tweet (no target)']
no_target_data = pd.DataFrame(data=new_array, columns=column)
no_target_data

def read_glove_vecs(glove_file):
    with open(glove_file, 'r', encoding='utf8') as f:
        words = set()
        word_to_vec_map = {}
        for line in f:
            line = line.strip().split()
            curr_word = line[0]
            words.add(curr_word)
            word_to_vec_map[curr_word] = np.array(line[1:], dtype=np.float64)
        i = 1
        words_to_index = {}
        index_to_words = {}
        for w in sorted(words):
            words_to_index[w] = i
            index_to_words[i] = w
            i = i + 1
    return (words_to_index, index_to_words, word_to_vec_map)

word_to_vec_map['sid']