tokenizer.texts_to_sepences(keras tokenizer)给出相同的预测

发布于 2025-02-09 02:23:12 字数 2194 浏览 2 评论 0 原文

看起来 tokenizer.toxts_texts_tox_to_to_sequencess_to_to_sepencess_to_to_sequessections 但这不是。 我正在努力创建一个文本分类代码,但我正在使用令牌机构面临一个预测的问题。

  1. 安装令牌仪,并使用该令牌将句子转换为(csv file-> pandas系列)的句子,以
tokenizer = Tokenizer()
tokenizer.fit_on_texts(X_train['clean_txt'])
X_train_seq = tokenizer.texts_to_sequences(X_train['clean_txt'])
X_test_seq = tokenizer.texts_to_sequences(X_test['clean_txt'])

#each sequence is the same length
pad_seq = 150
X_train_seq_padded = pad_sequences(X_train_seq, pad_seq)
X_test_seq_padded = pad_sequences(X_test_seq, pad_seq)
  1. 构建和评估一个顺序模型,
  2. 我做了一些预测,结果(x_test的未看到数据)是正确的:
model.predict(X_test_seq_padded[52].reshape(1, pad_seq))
array([[2.5905947e-05]], dtype=float32)

然后我尝试了在2个不同的原始字符串中有预测,我意识到我得到了相同的结果:

text = 'create a text classification code'
text = [text]
token_seq = tokenizer.texts_to_sequences(text)
token_seq_padded = pad_sequences(token_seq, pad_seq)
pred1 = model.predict(token_seq_padded)
pred1
array([[0.7042249]], dtype=float32)
token_seq
[[]]         <--- empty!!

我使用在此处找到的代码块(顶部的链接),并且具有不同的字符串的结果:有不同的字符串:

new_sample = ['Mathematics can describe many phenomena and concepts in music']
seq = tokenizer.texts_to_sequences(new_sample )
padded = pad_sequences(seq, maxlen=pad_seq)
pred = model.predict(padded)
pred
array([[0.7042249]], dtype=float32)
seq
[[]]         <--- empty!!

有了我的测试数据,好的结果,

precision    recall  f1-score   support

           0       0.98      0.99      0.98      1757
           1       0.97      0.95      0.96       809

    accuracy                           0.98      2566
   macro avg       0.98      0.97      0.97      2566
weighted avg       0.98      0.98      0.98      2566

我看不到什么,导致我取得错误的结果? tnx !!

It looks like to the same problem with this tokenizer.texts_to_sequences Keras Tokenizer gives almost all zeros
but it's not.
I am working to create a text classification code but I'm facing a predicting problem in new stings using the tokenizer.

  1. Fit the tokenizer and use that tokenizer to convert the sentences (of a csv file->Pandas series) to sequences
tokenizer = Tokenizer()
tokenizer.fit_on_texts(X_train['clean_txt'])
X_train_seq = tokenizer.texts_to_sequences(X_train['clean_txt'])
X_test_seq = tokenizer.texts_to_sequences(X_test['clean_txt'])

#each sequence is the same length
pad_seq = 150
X_train_seq_padded = pad_sequences(X_train_seq, pad_seq)
X_test_seq_padded = pad_sequences(X_test_seq, pad_seq)
  1. Build And Evaluate a Sequential model
  2. I made some predicts and the result (unseen data from X_test) were right:
model.predict(X_test_seq_padded[52].reshape(1, pad_seq))
array([[2.5905947e-05]], dtype=float32)

Then I tried to have predictions in 2 different raw strings and I realized that I am getting the same result:

text = 'create a text classification code'
text = [text]
token_seq = tokenizer.texts_to_sequences(text)
token_seq_padded = pad_sequences(token_seq, pad_seq)
pred1 = model.predict(token_seq_padded)
pred1
array([[0.7042249]], dtype=float32)
token_seq
[[]]         <--- empty!!

I use a block of code that I found here (the link at the top) and have the same result with different string:

new_sample = ['Mathematics can describe many phenomena and concepts in music']
seq = tokenizer.texts_to_sequences(new_sample )
padded = pad_sequences(seq, maxlen=pad_seq)
pred = model.predict(padded)
pred
array([[0.7042249]], dtype=float32)
seq
[[]]         <--- empty!!

With my test data I have good results

precision    recall  f1-score   support

           0       0.98      0.99      0.98      1757
           1       0.97      0.95      0.96       809

    accuracy                           0.98      2566
   macro avg       0.98      0.97      0.97      2566
weighted avg       0.98      0.98      0.98      2566

What is that I can't see, leading me in wrong results? Tnx!!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文