elastic search
This commit is contained in:
parent
d2096157b9
commit
efa3663f42
6 changed files with 87 additions and 67 deletions
|
|
@ -34,3 +34,5 @@ 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
|
||||
|
||||
https://pytorch.org/tutorials/intermediate/char_rnn_generation_tutorial.html
|
||||
|
|
@ -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": {
|
||||
|
|
|
|||
BIN
histogram.png
BIN
histogram.png
Binary file not shown.
|
Before Width: | Height: | Size: 106 KiB After Width: | Height: | Size: 52 KiB |
Binary file not shown.
|
|
@ -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,8 +104,75 @@ 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')
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue