diff --git a/README.md b/README.md index 6bb902c..08e269d 100644 --- a/README.md +++ b/README.md @@ -33,4 +33,6 @@ https://www.kaggle.com/code/leekahwin/text-classification-using-n-gram-0-8-f1 https://pytorch.org/tutorials/beginner/former_torchies/nnft_tutorial.html -https://github.com/pytorch/examples/blob/main/word_language_model/main.py \ No newline at end of file +https://github.com/pytorch/examples/blob/main/word_language_model/main.py + +https://pytorch.org/tutorials/intermediate/char_rnn_generation_tutorial.html \ No newline at end of file diff --git a/fetchDatafromDb/getProductDescriptionCat.es b/fetchDatafromDb/getProductDescriptionCat.es index 278f7f4..cd79123 100644 --- a/fetchDatafromDb/getProductDescriptionCat.es +++ b/fetchDatafromDb/getProductDescriptionCat.es @@ -1,6 +1,6 @@ Get retromotion-indexer_development_products/_search { - "_source":["descriptions","descriptionsSource","nameSource","shortDescriptionSource","categoriesSource"], + "_source":["_id","descriptions","descriptionsSource","nameSource","shortDescriptionSource","categoriesSource"], "query": { "match_all":{} // "bool": { diff --git a/histogram.png b/histogram.png index a8ef6e1..cf8c027 100644 Binary files a/histogram.png and b/histogram.png differ diff --git a/ngram-rnn-classification.pt b/ngram-rnn-classification.pt index 7787cb8..8d8e7df 100644 Binary files a/ngram-rnn-classification.pt and b/ngram-rnn-classification.pt differ diff --git a/rm_clasificationmodel/DataFrameClass.py b/rm_clasificationmodel/DataFrameClass.py index 50a5569..f3ad639 100644 --- a/rm_clasificationmodel/DataFrameClass.py +++ b/rm_clasificationmodel/DataFrameClass.py @@ -46,15 +46,16 @@ class DataFrame: def create(self): - self.df_eng = pd.DataFrame(columns=['name','category']) + self.df_eng = pd.DataFrame(columns=["id",'name','category']) self.df_de = pd.DataFrame(columns=['name','category']) - resp=self.es.search("retromotion-indexer_development_products",{"_source":["descriptions","descriptionsSource","nameSource","shortDescriptionSource","categoriesSource"], + resp=self.es.search("retromotion-indexer_development_products",{"_source":["_id","descriptions","descriptionsSource","nameSource","shortDescriptionSource","categoriesSource"], 'size' : 65000, "query": {"match_all": {}}}) for hit in resp['hits']['hits']: - list_row_en = dict (name=None,category=None) + list_row_en = dict (id=None,name=None,category=None) list_row_de = dict (name=None,category=None) + list_row_en["id"]=hit['_id'] for name in hit['_source']['nameSource']: if (name["language"]=="en"): list_row_en["name"]=name["value"] @@ -79,7 +80,11 @@ class DataFrame: self.df_de=pd.concat([self.df_de, new_row.to_frame().T], ignore_index=True) # df_eng.loc[len(df_eng)] = list_row + docDict = self.df_eng.to_dict(orient="records") + self.createIndexerProductCategory(docDict) + self.clean() + return [self.df_eng,self.df_de] def getNormal(self): @@ -99,9 +104,76 @@ class DataFrame: return self.df_eng + def getProductTaxonomy(self,_from,_size): + + self.df_taxonomy_all_en = pd.DataFrame(columns=['id','name','category']) + resp=self.es.search("english-taxonomy-all",{"_source":["id","name","category"], + 'from':_from, + 'size' :_size , + "query": {"match_all": {}}}) + for hit in resp['hits']['hits']: + list_row_en = dict (id=None,name=None,category=None) + list_row_en["name"]=hit['_source']['name'] + list_row_en["category"]=hit['_source']['category'] + + new_row = pd.Series(list_row_en) + self.df_taxonomy_all_en=pd.concat([self.df_taxonomy_all_en, new_row.to_frame().T], ignore_index=True) + + + + return self.df_taxonomy_all_en + def createIndexerTaxonomy(self,docDict): + request_body = { + "settings": { + "number_of_shards": 5, + "number_of_replicas": 1 + }, + 'mappings': { + "product_taxonomy": { + + 'properties': { + 'name': {'type': 'text'}, + 'category': {'type': 'text'}, + } + } + + } + } + + self.es.create('english-taxonomy-normal',request_body) + + for val in docDict: + + self.es.ingest('english-taxonomy-normal',val,'product_taxonomy') + + def createIndexerProductCategory(self,docDict): + request_body = { + "settings": { + "number_of_shards": 5, + "number_of_replicas": 1 + }, + 'mappings': { + "product_category": { + + 'properties': { + 'id': {'type': 'text'}, + 'name': {'type': 'text'}, + 'category': {'type': 'text'}, + } + } + } + } + + self.es.create('english-taxonomy-all',request_body) + + + for val in docDict: + + self.es.ingest('english-taxonomy-all',val,'product_category') + diff --git a/rm_clasificationmodel/main.py b/rm_clasificationmodel/main.py index 584b0d4..f96ab9a 100644 --- a/rm_clasificationmodel/main.py +++ b/rm_clasificationmodel/main.py @@ -10,78 +10,24 @@ from evaluate import Evaluate def main(): - # es =ElasticSearchDb("http://172.17.212.35:9200") - es_local =ElasticSearchDb("http://192.168.0.30:9200") + es =ElasticSearchDb("http://172.17.212.35:9200") + df=DataFrame(es) + dfProductTaxonomyEn=df.getProductTaxonomy(0,10000) - df=DataFrame(es_local) - - df.getNormal() - - df_en = df.getNormal() + + # df_en = df.getNormal() # [df_en, df_de]=df.create() - # docDict = df_en.to_dict(orient='records') - - # request_body = { - # "settings": { - # "number_of_shards": 5, - # "number_of_replicas": 1 - # }, - # 'mappings': { - # "product_taxonomy": { - - # 'properties': { - # 'name': {'type': 'text'}, - # 'category': {'type': 'text'}, - # } - # } - - # } - # } - - # es_local.create('english-taxonomy-normal',request_body) - # for val in docDict: - # print (val) - # es_local.ingest('english-taxonomy-normal',val,'product_taxonomy') - - - - - - - # vectorizer = Vectorize(1,1) - # vectorizer.setTfidFitTransform(df_en["name"]) - - # x =vectorizer.getTfidFitTransform() - - # print(x.shape) - - # vectorizer.fit(doc=df_en["name"]) - - # vectorizer.transform(df_en["name"]) - - # df =df_eng["category"].isnull() - - # bool_name_series = pd.notnull(df_eng["name"]) - # bool_cat_series = pd.isnull(df_eng["name"]) - # print(df_eng[bool_cat_series]) - # inputSize=vectorizer.getTransformedVectorSize() - # n_hidden = 256*4 - # df_category = df_en.groupby('category') - # all_category = list(df_category.groups.keys()) - # n_category = len(all_category) - # rnn=RNN(inputSize, n_hidden, n_category) - # rnn=torch.load('ngram-rnn-classification.pt') - train = Train(df_en) - train.run(90000) - train.predict('vaico centering bush propshaft',2) + # train = Train(df_en) + # train.run(20) + # train.predict('vaico centering bush propshaft',2)