- Windows System (Tested on Windows 10)
pdflatex
TexLive (/wstandalone
package)magick
Image Magickchoco install imagemagick
gswin32c
Ghost Script (x86)
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
class AttentionWithContext(Layer): | |
""" | |
Attention operation, with a context/query vector, for temporal data. | |
Supports Masking. | |
Follows the work of Yang et al. [https://www.cs.cmu.edu/~diyiy/docs/naacl16.pdf] | |
"Hierarchical Attention Networks for Document Classification" | |
by using a context vector to assist the attention | |
# Input shape | |
3D tensor with shape: `(samples, steps, features)`. | |
# Output shape |
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
#! encoding=UTF-8 | |
""" | |
kernel canonical correlation analysis | |
""" | |
import numpy as np | |
from scipy.linalg import svd | |
from sklearn.metrics.pairwise import pairwise_kernels, euclidean_distances | |
class KCCA(object): |
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 | |
data = pd.read_csv("file.csv", sep=",") | |
print(data.head(2)) | |
with open('file.json', 'w') as f: | |
f.write(data.to_json(orient='records', lines=True)) | |
# check | |
data = pd.read_json("file.json", lines=True) | |
print(data.head(2)) |
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
from ekphrasis.classes.preprocessor import TextPreProcessor | |
from ekphrasis.classes.tokenizer import SocialTokenizer | |
from ekphrasis.dicts.emoticons import emoticons | |
import numpy as np | |
import re | |
import io | |
label2emotion = {0: "others", 1: "happy", 2: "sad", 3: "angry"} | |
emotion2label = {"others": 0, "happy": 1, "sad": 2, "angry": 3} |
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 spacy | |
from spacy.lang.pt.stop_words import STOP_WORDS | |
from sklearn.feature_extraction.text import CountVectorizer | |
import pt_core_news_sm | |
nlp = pt_core_news_sm.load() | |
with open("original_text.txt", "r", encoding="utf-8") as f: | |
text = " ".join(f.readlines()) | |
doc = nlp(text) |
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
corpus = [sent.text.lower() for sent in doc.sents ] | |
cv = CountVectorizer(stop_words=list(STOP_WORDS)) | |
cv_fit=cv.fit_transform(corpus) | |
word_list = cv.get_feature_names(); | |
count_list = cv_fit.toarray().sum(axis=0) | |
"""The zip(*iterables) function takes iterables as arguments and returns an iterator. | |
This iterator generates a series of tuples containing elements from each iterable. | |
Let's convert these tuples to {word:frequency} dictionary""" |
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
val=sorted(word_frequency.values()) | |
higher_word_frequencies = [word for word,freq in word_frequency.items() if freq in val[-3:]] | |
print("\nWords with higher frequencies: ", higher_word_frequencies) | |
# gets relative frequencies of words | |
higher_frequency = val[-1] | |
for word in word_frequency.keys(): | |
word_frequency[word] = (word_frequency[word]/higher_frequency) |
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
sentence_rank={} | |
for sent in doc.sents: | |
for word in sent : | |
if word.text.lower() in word_frequency.keys(): | |
if sent in sentence_rank.keys(): | |
sentence_rank[sent]+=word_frequency[word.text.lower()] | |
else: | |
sentence_rank[sent]=word_frequency[word.text.lower()] | |
top_sentences=(sorted(sentence_rank.values())[::-1]) |
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
summary=[] | |
for sent,strength in sentence_rank.items(): | |
if strength in top_sent: | |
summary.append(sent) | |
else: | |
continue | |
for i in summary: | |
print(i,end=" ") |