numpy C3W2_在coursera中的作业深度学习课程NLP

x33g5p2x  于 2023-10-19  发布在  其他
关注(0)|答案(1)|浏览(126)

grader-required-cell

分级功能:标记化标签

def tokenize_labels(all_labels,split_labels):“”标记标签

Args:
    all_labels (list of string): labels to generate the word-index from
    split_labels (list of string): labels to tokenize

Returns:
    label_seq_np (array of int): tokenized labels
"""

### START CODE HERE

# Instantiate the Tokenizer (no additional arguments needed)
label_tokenizer = Tokenizer()

# Fit the tokenizer on all the labels
label_tokenizer.fit_on_texts(all_labels)

# Convert labels to sequences
label_seq = label_tokenizer.texts_to_sequences(split_labels)

# Convert sequences to a numpy array. Don't forget to substact 1 from every entry in the array!
label_seq_np = np.array(label_seq)-1 <----------- i don't know what is wrong

### END CODE HERE

return label_seq_np

输出为:
TypeError:不支持的操作数类型-:'list'和'int'

zlhcx6iw

zlhcx6iw1#

尝试:

label_seq_minus_one = [[num - 1 for num in seq] for seq in label_seq]

label_seq_np = np.array(label_seq_minus_one)

相关问题