-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCorpus.py
43 lines (33 loc) · 1.24 KB
/
Corpus.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import string
import nltk
from nltk.corpus import cess_esp #Corpus español
from nltk.corpus import stopwords
from nltk.corpus import brown
nltk.download('stopwords')
nltk.download('cess_esp')
#nltk.download('cess_esp')
#from transformer import transformer_model
import matplotlib.pyplot as plt
from collections import defaultdict
from elotl.corpus import load
from seaborn import heatmap
import BPE #Se importa el módulo del algoritmo.
#Pasamos el corpus a minúsculas.
corpus = [i.lower() for i in cess_esp.words()]
tokens = len(corpus)
tipos = len(set(corpus))
print('Número de tókens: ', tokens)
print('Número de tipos: ', tipos)
#Se eliminan caracteres y cadenas que no sean puramente letras.
#e.g. signos de exclamación, interrogación, etc.
clean_corpus = [i for i in corpus if i.isalpha()]
#Se eliminan las stopwords en español del corpus.
stopwords = set(stopwords.words('spanish'))
clean_corpus = [i for i in clean_corpus if i not in stopwords]
#Se separan las palabras en caracteres separados por espacios.
clean_corpus = [' '.join(list(x)) for x in clean_corpus]
clean_corpus = BPE.BPE(clean_corpus[:100], 20)
for i in range(len(clean_corpus)):
print(clean_corpus[i])
#Descomentar para imprimir el corpus actualizado.
#print(clean_corpus)