Exemplo n.º 1
0
    run_parser.add_argument('--threads', type=int, metavar='num', required=False,
                            default=1, help="Maximum number of threads to use.")

    args = parse_args(parser, commands)

    if os.path.exists(args.run.topics) and args.run.topics.endswith('.json'):
        topics = json.load(open(args.run.topics))
    else:
        topics = get_topics(args.run.topics)
    # invalid topics name
    if topics == {}:
        print(f'Topic {args.run.topics} Not Found')
        exit()

    query_encoder = init_query_encoder(args.dense.encoder,
                                       args.run.topics,
                                       args.dense.encoded_queries,
                                       args.dense.device)
    if not query_encoder:
        print(f'No encoded queries for topic {args.run.topics}')
        exit()

    if os.path.exists(args.dense.index):
        # create searcher from index directory
        dsearcher = SimpleDenseSearcher(args.dense.index, query_encoder)
    else:
        # create searcher from prebuilt index name
        dsearcher = SimpleDenseSearcher.from_prebuilt_index(args.dense.index, query_encoder)

    if not dsearcher:
        exit()
Exemplo n.º 2
0
    run_parser.add_argument('--threads',
                            type=int,
                            metavar='num',
                            required=False,
                            default=1,
                            help="Maximum number of threads to use.")

    args = parse_args(parser, commands)

    query_iterator = get_query_iterator(args.run.topics,
                                        TopicsFormat(args.run.topics_format))
    topics = query_iterator.topics

    query_encoder = init_query_encoder(args.dense.encoder,
                                       args.dense.tokenizer, args.run.topics,
                                       args.dense.encoded_queries,
                                       args.dense.device,
                                       args.dense.query_prefix)

    if os.path.exists(args.dense.index):
        # create searcher from index directory
        dsearcher = SimpleDenseSearcher(args.dense.index, query_encoder)
    else:
        # create searcher from prebuilt index name
        dsearcher = SimpleDenseSearcher.from_prebuilt_index(
            args.dense.index, query_encoder)

    if not dsearcher:
        exit()

    if os.path.exists(args.sparse.index):