szha commented on a change in pull request #8763: [WIP] Add text apis
URL: https://github.com/apache/incubator-mxnet/pull/8763#discussion_r155904593
 
 

 ##########
 File path: python/mxnet/text/glossary.py
 ##########
 @@ -0,0 +1,654 @@
+# 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.
+
+"""Read text files and load embeddings."""
+from __future__ import absolute_import
+from __future__ import print_function
+
+import logging
+import os
+import tarfile
+import zipfile
+
+from ..gluon.utils import check_sha1
+from ..gluon.utils import download
+from .. import ndarray as nd
+
+from tqdm import tqdm
+
+
+class Glossary(object):
+    """Indexing and embedding for text and special tokens in a glossary.
+
+    For each indexed text or special token (e.g., an unknown token) in a
+    glossary, an embedding vector will be associated with the token. Such
+    embedding vectors can be loaded from externally pre-trained embeddings,
+    such as via mxnet.text.Embedding instances.
+
+
+    Parameters
+    ----------
+    counter : collections.Counter
+        Counts text token frequencies in the text data.
+    top_k_freq : None or int, default None
+        The number of top frequent tokens in the keys of `counter` that will be
+        indexed. If None, all the tokens in the keys of `counter` will be
+        indexed.
+    min_freq : int, default 1
+        The minimum frequency required for a token in the keys of `counter` to
+        be indexed.
+    specials : list of strs, default ['<unk>']
+        A list of special tokens to be indexed. It must be an non-empty list
+        whose first element is the string representation for unknown tokens,
+        such as '<unk>'. It cannot contain any token from the keys of 
`counter`.
+    embeds : an mxnet.text.Embedding instance, a list of mxnet.text.Embedding
+             instances, or None, default None
+        Pre-trained embeddings to load. If None, there is nothing to load.
+
+
+    Properties
+    ----------
+    counter : collections.Counter
+        Counts text and special token frequencies in the text data, where
+        special token frequency is clear to zero.
 
 Review comment:
   Given that this came from user, it?s probably not necessary to expose the 
counter as a property. Otherwise we need to define how this property should 
change based on topk or other constructor arguments, and define how mutating 
this property means.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to