缺失函数keras.sequence.来自tensorflow库的Pad_sequences



实际上有可能从库中丢失的方法之一,而它应该在那里?

from keras.preprocessing import sequence
features_train = sequence.pad_sequences(data_train, maxlen=400)

AttributeError                            Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 features_train = sequence.pad_sequences(data_train, maxlen=400)
2 features_test = sequence.pad_sequences(data_test, maxlen=400)
AttributeError: module 'keras.preprocessing.sequence' has no attribute 'pad_sequences'

我检查了帮助,但功能不在那里

FUNCTIONS

make_sampling_table(大小、sampling_factor = 1 e-05)生成一个基于单词排名的概率抽样表。

Used for generating the `sampling_table` argument for `skipgrams`.
`sampling_table[i]` is the probability of sampling
the word i-th most common word in a dataset
(more common words should be sampled less frequently, for balance).

The sampling probabilities are generated according
to the sampling distribution used in word2vec:

```
p(word) = (min(1, sqrt(word_frequency / sampling_factor) /
(word_frequency / sampling_factor)))
```

We assume that the word frequencies follow Zipf's law (s=1) to derive
a numerical approximation of frequency(rank):

`frequency(rank) ~ 1/(rank * (log(rank) + gamma) + 1/2 - 1/(12*rank))`
where `gamma` is the Euler-Mascheroni constant.

Args:
size: Int, number of possible words to sample.
sampling_factor: The sampling factor in the word2vec formula.

Returns:
A 1D Numpy array of length `size` where the ith entry
is the probability that a word of rank i should be sampled.

skipgrams(sequence, vocabulary_size, window_size=4, negative_samples=1.0, shuffle=True, categorical=False, sampling_table=None, seed=None)生成跳跃图词对。

This function transforms a sequence of word indexes (list of integers)
into tuples of words of the form:

- (word, word in the same window), with label 1 (positive samples).
- (word, random word from the vocabulary), with label 0 (negative samples).

Read more about Skipgram in this gnomic paper by Mikolov et al.:
[Efficient Estimation of Word Representations in
Vector Space](http://arxiv.org/pdf/1301.3781v3.pdf)

Args:
sequence: A word sequence (sentence), encoded as a list
of word indices (integers). If using a `sampling_table`,
word indices are expected to match the rank
of the words in a reference dataset (e.g. 10 would encode
the 10-th most frequently occurring token).
Note that index 0 is expected to be a non-word and will be skipped.
vocabulary_size: Int, maximum possible word index + 1
window_size: Int, size of sampling windows (technically half-window).
The window of a word `w_i` will be
`[i - window_size, i + window_size+1]`.
negative_samples: Float >= 0. 0 for no negative (i.e. random) samples.
1 for same number as positive samples.
shuffle: Whether to shuffle the word couples before returning them.
categorical: bool. if False, labels will be
integers (eg. `[0, 1, 1 .. ]`),
if `True`, labels will be categorical, e.g.
`[[1,0],[0,1],[0,1] .. ]`.
sampling_table: 1D array of size `vocabulary_size` where the entry i
encodes the probability to sample a word of rank i.
seed: Random seed.

Returns:
couples, labels: where `couples` are int pairs and
`labels` are either 0 or 1.

Note:
By convention, index 0 in the vocabulary is
a non-word and will be skipped.

虽然很明显,对于tensorflow 2.9.0(我现在使用的版本),从他们的网站应该可用的功能是:类类TimeseriesGenerator:用于生成批量时态数据的实用程序类。

功能make_sampling_table(…):生成一个基于单词排名的概率抽样表。

pad_sequences(…):填充相同长度的序列。

skipgrams(…):生成略图词对。

那么这是由于安装失败还是其他原因引起的?因为我从来没有遇到过这样的问题,甚至在网上也找不到任何参考

我也有同样的问题,我使用

修复了它
keras.utils.data_utils.pad_sequences 

我想他们把它从keras。sequence

希望我能帮上忙:)

代替keras.预处理.sequence.pad_sequencesPip install keras-preprocessing

from keras_preprocessing import pad_sequences

可能有任何帮助

相关内容

  • 没有找到相关文章

最新更新