Spanish¶
The first text model created is based on tweets collected from December 2015 until February 2020. From this collection we randomly selected approximately 5,000,000, excluding retweets and tweets having less than two words, to create the text model. The text model is created using the following paramters.
from b4msa.textmodel import TextModel
tm = TextModel(usr_option="delete",
num_option="delete",
url_option="delete",
emo_option="none",
token_min_filter=0.001,
token_max_filter=0.999)
The aforementioned model is a bag of word model, where the number of tokens is 15,227 (i.e., \(m_b: \text{text} \rightarrow \mathbb R^{15227}\)).
This model (without using the text model trained with the training set) can be used as follow:
>>> from EvoMSA.base import EvoMSA
>>> evo = EvoMSA(TR=False, B4MSA=True, lang='es')
The next table shows the different models we have produced for the Spanish language.
The following code shows the usage of two of the models with suffix .evomsa. The models used are haha2018_Es.evomsa, mexa3t2018_aggress_Es.evomsa, as well as \(m_b\) text-model, and without the text model obtained with the training set.
>>> from EvoMSA.utils import download
>>> from EvoMSA.base import EvoMSA
>>> from microtc.utils import tweet_iterator
>>> import os
>>> tweets = os.path.join(os.path.dirname(base.__file__), 'tests', 'tweets.json')
>>> D = list(tweet_iterator(tweets))
>>> X = [x['text'] for x in D]
>>> y = [x['klass'] for x in D]
>>> haha = download('haha2018_Es.evomsa')
>>> mexa3t = download('mexa3t2018_aggress_Es.evomsa')
>>> evo = EvoMSA(TR=False, B4MSA=True, lang='es',
models=[[haha, "sklearn.svm.LinearSVC"],
[mexa3t, "sklearn.svm.LinearSVC"]])
>>> evo.fit(X, y)
where sklearn.svm.LinearSVC
can be any classifier following the structure of sklearn.
Predict a sentence in Spanish
>>> evo.predict(['EvoMSA esta funcionando'])