Получение приблизительной оценки каппы с использованием ElasticSearch и MinHash tokenf ilter - PullRequest
0 голосов
/ 13 марта 2019

Я хочу получить похожие документы, используя фильтр токенов MinHash .Я создал следующий индекс, который использует токенайзер пробелов и затем хэширует каждый токен:

{
  "settings": {
    "analysis": {
      "filter": {
        "my_minhash_filter": {
          "type": "min_hash",
          "hash_count": 1,   
          "bucket_count": 128, 
          "hash_set_size": 1, 
          "with_rotation": true 
        }
      },
      "analyzer": {
        "my_analyzer": {
          "type": "custom",
          "tokenizer": "whitespace",
          "filter": [
            "my_minhash_filter"
          ]
        }
      }
    }
  },
  "mappings": {
      "_doc": {
        "properties": {
          "title": {
            "type": "text",
            "analyzer": "my_analyzer",
            "search_analyzer": "my_analyzer"
          }
        }
      }
  }
}

Впоследствии я добавил набор данных из 20 групп новостей в базу данныхasticsearch

from elasticsearch import Elasticsearch
from sklearn.datasets import fetch_20newsgroups

twenty_train = fetch_20newsgroups(subset='train', shuffle=True, random_state=42)
es = Elasticsearch([{'host': 'localhost', 'port': 9200}])

for index, example in enumerate(twenty_train['data']):
    es.create(index='test_analyzer', doc_type='_doc', id=index, body={"title": example})

Это действительно кажетсяиспользовать токен-фильтр MinHash, но ответы довольно странные.Например, когда я запрашиваю один из точных элементов, я получаю следующий результат:

{
    "query": {
        "match": {
            "title": "From: steve@titan.tsd.arlut.utexas.edu (Steve Glicker)\nSubject: 2 1000W Power Supplies\nNntp-Posting-Host: rooster\nOrganization: Applied Research Labs, The University of Texas at Austin\nDistribution: misc\nLines: 14\n\nTwo LH Research SM11-1 power supplies (SM10 series).\n\n1000W, 5V, 200A (currently wired for 115VAC)\n\nControl lines: +/- sense, on/off, pwr.fail, high/low margin, and\ncurrent monitor.\n\n(The list price from LH Research is $824.00 each for qty. 1-9)\n\nAsking $500.00 for the pair.\n\nSteve Glicker\nAustin, Texas\n(steve@titan.tsd.arlut.utexas.edu)\n"
        }
    }
}

Answer:
{
    "took": 8,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": 10999,
        "max_score": 0.6097297,
        "hits": [
            {
                "_index": "test_analyzer",
                "_type": "_doc",
                "_id": "8161",
                "_score": 0.6097297,
                "_source": {
                    "title": "From: steve@titan.tsd.arlut.utexas.edu (Steve Glicker)\nSubject: 2 1000W Power Supplies\nNntp-Posting-Host: rooster\nOrganization: Applied Research Labs, The University of Texas at Austin\nDistribution: misc\nLines: 14\n\nTwo LH Research SM11-1 power supplies (SM10 series).\n\n1000W, 5V, 200A (currently wired for 115VAC)\n\nControl lines: +/- sense, on/off, pwr.fail, high/low margin, and\ncurrent monitor.\n\n(The list price from LH Research is $824.00 each for qty. 1-9)\n\nAsking $500.00 for the pair.\n\nSteve Glicker\nAustin, Texas\n(steve@titan.tsd.arlut.utexas.edu)\n"
                }
            },
            {
                "_index": "test_analyzer",
                "_type": "_doc",
                "_id": "8901",
                "_score": 0.60938174,
                "_source": {
                    "title": "Organization: City University of New York\nFrom: <F36SI@CUNYVM.BITNET>\nSubject: Model United Nations\nLines: 3\n\n    Just observed at the National Model United Nations here in NYC.\n    Just one word on it : AWSOME.\n                                 Peace, matt\n"
                }
            },
....

Первый результат, как и ожидалось, - это фактическое сообщение, которое я искал.Тем не менее, он не имеет балл намного выше, чем следующий пункт, который гораздо больше отличается.Как я могу запросить эту базу данных таким образом, чтобы я получал только те тексты, у которых приблизительная оценка каппа выше определенного порога?

Я пробовал поискать в Google, но, к сожалению, информации о том, как использовать MinHash для поиска похожих предметов, очень мало.

Заранее спасибо!

...