Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week1 - PR #1

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified opensearch/ltr_toy_model.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
280 changes: 280 additions & 0 deletions week1/conf/ltr_featureset.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,286 @@
"name": "{{keywords}}"
}
}
},
{
"name": "manufacturer_phrase_match",
"params": [
"keywords"
],
"template_language": "mustache",
"template": {
"match_phrase": {
"manufacturer": {
"query": "{{keywords}}",
"slop": 6
}
}
}
},
{
"name": "dept_phrase_match",
"params": [
"keywords"
],
"template_language": "mustache",
"template": {
"match_phrase": {
"department": {
"query": "{{keywords}}",
"slop": 6
}
}
}
},
{
"name": "category_path_phrase_match",
"params": [
"keywords"
],
"template_language": "mustache",
"template": {
"match_phrase": {
"categoryPath": {
"query": "{{keywords}}",
"slop": 6
}
}
}
},
{
"name": "class_phrase_match",
"params": [
"keywords"
],
"template_language": "mustache",
"template": {
"match_phrase": {
"class": {
"query": "{{keywords}}",
"slop": 6
}
}
}
},
{
"name": "name_phrase_match",
"params": [
"keywords"
],
"template_language": "mustache",
"template": {
"match_phrase": {
"name": {
"query": "{{keywords}}",
"slop": 6
}
}
}
},
{
"name": "customer_review_avg",
"template_language": "mustache",
"template": {
"function_score": {
"functions": [
{
"field_value_factor": {
"field": "customerReviewAverage",
"missing": 4.0
}
}
],
"query": {
"match_all": {}
}
}
}
},
{
"name": "customer_review_count",
"template_language": "mustache",
"template": {
"function_score": {
"functions": [
{
"field_value_factor": {
"field": "customerReviewCount",
"missing": 9
}
}
],
"query": {
"match_all": {}
}
}
}
},
{
"name": "artist_name_phrase_match",
"params": [
"keywords"
],
"template_language": "mustache",
"template": {
"match_phrase": {
"artistName": {
"query": "{{keywords}}",
"slop": 6
}
}
}
},
{
"name": "short_description_phrase_match",
"params": [
"keywords"
],
"template_language": "mustache",
"template": {
"match_phrase": {
"shortDescription": {
"query": "{{keywords}}",
"slop": 6
}
}
}
},
{
"name": "long_description_phrase_match",
"params": [
"keywords"
],
"template_language": "mustache",
"template": {
"match_phrase": {
"longDescription": {
"query": "{{keywords}}",
"slop": 6
}
}
}
},
{
"name": "salesRankShortTerm",
"template_language": "mustache",
"template": {
"function_score": {
"functions": [
{
"filter": {
"exists": {
"field": "salesRankShortTerm"
}
},
"gauss": {
"salesRankShortTerm": {
"origin": "1.0",
"offset": "100",
"scale": "10000",
"decay": "0.1"
}
}
},
{
"filter": {
"bool": {
"must_not": {
"exists": {
"field": "salesRankShortTerm"
}
}
}
},
"script_score": {
"script": "if (doc['salesRankShortTerm'] == null || doc['salesRankShortTerm'].size() == 0 ){return 0.0}"
}
}
],
"query": {
"match_all": {}
}
}
}
},
{
"name": "in_store_availability",
"template_language": "mustache",
"template": {
"function_score": {
"query": { "match_all": {} },
"functions": [
{
"filter": { "match": { "inStoreAvailability": "true" } },
"weight": 1
},
{
"weight": 0
}
],
"score_mode": "max",
"min_score": 0
}
}
},
{
"name": "online_availability",
"template_language": "mustache",
"template": {
"function_score": {
"query": { "match_all": {} },
"functions": [
{
"filter": { "match": { "onlineAvailability": "true" } },
"weight": 1
},
{
"weight": 0
}
],
"score_mode": "max",
"min_score": 0
}
}
},
{
"name": "on_sale",
"template_language": "mustache",
"template": {
"function_score": {
"query": { "match_all": {} },
"functions": [
{
"filter": { "match": { "onSale": "true" } },
"weight": 1
},
{
"weight": 0
}
],
"score_mode": "max",
"min_score": 0
}
}
},
{
"name": "digital",
"template_language": "mustache",
"template": {
"function_score": {
"query": { "match_all": {} },
"functions": [
{
"filter": { "match": { "digital": "true" } },
"weight": 1
},
{
"weight": 0
}
],
"score_mode": "max",
"min_score": 0
}
}
}
]
}
Expand Down
37 changes: 37 additions & 0 deletions week1/test/week1test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

hits=[
{
'_index': 'searchml_ltr',
'_id': 'doc_e',
'_score': 0.0,
'_source': {
'id': 'doc_e',
'title': 'Pigs in a Blanket and Other Recipes',
'price': '27.50',
'in_stock': True,
'body': "Pigs in a blanket aren't as cute as you would think given it's a food and not actual pigs wrapped in blankets.",
'category': 'instructional'
},
'fields': {
'_ltrlog': [
{
'log_entry': [
{'name': 'title_query', 'value': 1.1272218},
{'name': 'body_query', 'value': 2.2908108},
{'name': 'price_func', 'value': 27.5}
]

}
]
},
'matched_queries': ['logged_featureset']
}
]

log_entries = hits[0]['fields']['_ltrlog'][0]['log_entry']

print(log_entries)

for entry in log_entries:
if entry['name'] == "title_query" :
print(entry['value'])
1 change: 0 additions & 1 deletion week1/utilities/build_ltr.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,6 @@
#############
if args.xgb:
# Defaults

bst, xgb_params = xgbu.train(args.xgb, args.xgb_rounds, args.xgb_conf)
print("Dumping out model using feature map: %s" % args.xgb_feat_map)
model = bst.get_dump(fmap=("%s/%s" % (output_dir, args.xgb_feat_map)), dump_format='json')
Expand Down
Loading