Answer the question
In order to leave comments, you need to log in
The "compiled" python code itself is restarted. How to fix?
I made a simple program (neural network) for classifying questions in python3, then "compiled" it to .elf via PyInstaller. Compiled with pyinstaller -F --hidden-import sklearn.neighbors.typedefs command. The problem is that at startup the program restarts every 5 seconds.
Here:
Введите вопрос:
#через 5 секунд
Введите вопроc:
---
UPD: вот код
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model import SGDClassifier
from sklearn.pipeline import Pipeline
from sklearn.metrics import accuracy_score
def clean(text):
text = " ".join(text.split())
text = text.strip()
return text
def load_dict():
data = { 'text':[],'tag':[] }
for line in open('q.txt'):
if(not('//' in line)):
row = line.split("@")
data['text'] += [row[0]]
data['tag'] += [row[1]]
return data
def train_test_split( data, validation_split = 0.1):
sz = len(data['text'])
indices = np.arange(sz)
np.random.shuffle(indices)
X = [ data['text'][i] for i in indices ]
Y = [ data['tag'][i] for i in indices ]
nb_validation_samples = int( validation_split * sz )
return {
'train': { 'x': X[:-nb_validation_samples], 'y': Y[:-nb_validation_samples] },
'test': { 'x': X[-nb_validation_samples:], 'y': Y[-nb_validation_samples:] }
}
def parse(text):
text =clean(text)
data = load_dict()
Data = train_test_split( data )
text_clf = Pipeline([
('tfidf', TfidfVectorizer()),
('clf', SGDClassifier(loss='hinge')),
])
text_clf.fit(Data['train']['x'], Data['train']['y'])
predicted = text_clf.predict( Data['train']['x'] )
zz=[]
zz.append(text)
predicted = Data = train_test_split( data )
text_clf = Pipeline([
('tfidf', TfidfVectorizer()),
('clf', SGDClassifier(loss='hinge')),
])
text_clf.fit(Data['train']['x'], Data['train']['y'])
predicted = text_clf.predict( Data['train']['x'] )
resp = predicted[0]
resp = resp.strip().replace("\n","")
return resp
a = parse(input("Введите вопрос: "))
print(str("Это "+a))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question