astonzhang commented on a change in pull request #8763: Add mxnet.text APIs URL: https://github.com/apache/incubator-mxnet/pull/8763#discussion_r160547553
########## File path: python/mxnet/text/glossary.py ########## @@ -0,0 +1,123 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +# coding: utf-8 + +"""Index text tokens and load their embeddings.""" +from __future__ import absolute_import +from __future__ import print_function + +from .. import ndarray as nd +from .embedding import TokenEmbedding + + +class Glossary(TokenEmbedding): + """Indexing and embedding for text tokens in a glossary. + + For each indexed token in a glossary, an embedding vector will be associated + with it. Such embedding vectors can be loaded from externally hosted or + custom pre-trained token embedding files, such as via instances of + :func:`~mxnet.text.embedding.TokenEmbedding`. + + + Parameters + ---------- + counter : collections.Counter or None, default None + Counts text token frequencies in the text data. Its keys will be indexed + according to frequency thresholds such as `most_freq_count` and + `min_freq`. Keys of `counter`, `unknown_token`, and values of + `reserved_tokens` must be the same type with __hash__() and __cmp__(). + Examples: str, int, and typle. + token_embeddings : an instance or a list of instances of + :func:`~mxnet.text.embedding.TokenEmbedding` + One or multiple pre-trained token embeddings to load. If it is a list of + multiple embeddings, these embedding vectors will be concatenated for + each token. + most_freq_count : None or int, default None + The maximum possible number of the most frequent tokens in the keys of + `counter` that can be indexed. Note that this argument does not count + any token from `reserved_tokens`. If this argument is None or larger + than its largest possible value restricted by `counter` and + `reserved_tokens`, this argument becomes positive infinity. + min_freq : int, default 1 + The minimum frequency required for a token in the keys of `counter` to + be indexed. + unknown_token : type with __hash__() and __cmp__(), default '<unk>' Review comment: resolved. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
