Сопоставить функцию с набором альфа-данных Tensorflow 2.0 - PullRequest
0 голосов
/ 27 мая 2019

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

dataset, info = tfds.load('cnn_dailymail', with_info=True, as_supervised=True)
train_dataset, test_dataset = dataset['train'], dataset['test']

# Converts the unicode file to ascii
def unicode_to_ascii(s):
    return ''.join(c for c in unicodedata.normalize('NFD', s)
        if unicodedata.category(c) != 'Mn')


def preprocess_sentence(w):
    w = unicode_to_ascii(w.lower().strip())

    w = re.sub(r"([?.!,¿])", r" \1 ", w)
    w = re.sub(r'[" "]+', " ", w)

    # replacing everything with space except (a-z, A-Z, ".", "?", "!", ",")
    w = re.sub(r"[^a-zA-Z?.!,¿]+", " ", w)

    w = w.rstrip().strip()

    # adding a start and an end token to the sentence
    # so that the model know when to start and stop predicting.
    w = '<start> ' + w + ' <end>'
    return w

def map_fn(x, label):
    article_text = tf.cast(x, tf.string).decode('utf-8')
    x = preprocess_sentence(article_text)
    return x, label

# taking a small batch to check
small_batch = train_dataset.batch(5)
small_batch = small_batch.map(map_fn)

И я получаю следующую ошибку: AttributeError: у объекта 'Tensor' нет атрибута 'decode'

Любая помощь в том, как я могу получить доступ к тексту, будет принята с благодарностью! ТИА

...