<jupyter_start><jupyter_text>Data<jupyter_code>from pandas import read_csv
data = read_csv("/kaggle/input/contexttopic-classification-from-statement/Context.csv")
data.head()<jupyter_output><empty_output><jupyter_text>Preprocessing (with ffast)<jupyter_code>!pip install ffast
from ffast import load
tokeniser = load('poincare')
small_data = data.head(100)
small_data['input'] = small_data['Text'].map(lambda text:tokeniser.encode(text).vector)
small_data['output'] = small_data['Context/Topic'].map(lambda topic:tokeniser.encode(topic).semantics()[-1])
small_data.head()<jupyter_output><empty_output><jupyter_text>Training (ML)<jupyter_code>from sklearn.neural_network import MLPRegressor
classifier = MLPRegressor(verbose=True, solver='adam', activation='tanh', tol=1e-8, n_iter_no_change=50, hidden_layer_sizes=(1000)*3)
classifier.fit(small_data['input'].to_list(),small_data['output'].to_list())
from matplotlib.pyplot import plot
plot(classifier.loss_curve_)<jupyter_output><empty_output><jupyter_text>Topic Classification<jupyter_code>topic_classification = lambda text: str(tokeniser.decode_semantics(classifier.predict([tokeniser.encode(text).vector])))
topic_classification("i love to listen to a good song")
topic_classification("nice day today")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13675213675213677, 'fraction_numerical': 0.010101010101010102, 'mean_word_length': 12.557894736842105, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '287905', 'license': 'MIT', 'n_tokens_mistral': 455, 'n_tokens_neox': 431, 'n_words': 58, 'path': 'examples/ffast_for_ml_regression.ipynb', 'repo_name': 'mohammedterryjack/ffast', 'size': '1287'}