longmaoteamtf / deep_recommenders Goto Github PK
View Code? Open in Web Editor NEWDeep Recommenders
License: Apache License 2.0
Deep Recommenders
License: Apache License 2.0
def corrected_batch_softmax(x, y, sampling_p=None):
"""logQ correction softmax"""
correct_inner_product = log_q(x, y, sampling_p=sampling_p)
return tf.math.exp(correct_inner_product) / tf.math.reduce_sum(tf.math.exp(correct_inner_product))
这里softmax计算的是不是有些问题呢?
原论文:
中分母是x_i与batch内不同y_j点乘的和, 而代码中分母是batch内x_i与y_i点乘的和
大佬,请问这个错误,是需要pip安装deep_recommenders吗
Hi, thank you so much for open sourcing your project, it helps me a lot!!
Here I just have one simple bug to report:
Source: 3rd code cell from notebook
outputs = Transformer(
vocab_size,
model_dim,
n_heads=2,
encoder_stack=2,
decoder_stack=2,
feed_forward_size=50
)([encoder_inputs, decoder_inputs])
After ran the notebook and traced your code (deep_recommenders/keras/models/nlp/Transformer.py
),
the input of Transformer class object needs 2 parameters (encoder_inputs, decoder_inputs), it should not be a list.
outputs = Transformer(
vocab_size,
model_dim,
n_heads=2,
encoder_stack=2,
decoder_stack=2,
feed_forward_size=50
)(encoder_inputs, decoder_inputs)
源码:
decoder_targets = np.zeros((len(answers_seqs), max_len, vocab_size), dtype='float32')
for i, seq in enumerate(answers_seqs):
for j, index in enumerate(seq):
if j > 0: decoder_targets[i, j-1, index-1] = 1
if index == 0: break
似乎是出问题在break处,因为padding为0,pad_sequences默认是 pre pad,所以遇见0 就break,导致decoder_targets未能成功赋值
class HardNegativeMining(tf.keras.layers.Layer):
"""Hard Negative"""
def __init__(self, num_hard_negatives: int, **kwargs):
super(HardNegativeMining, self).__init__(**kwargs)
self._num_hard_negatives = num_hard_negatives
def call(self, logits: tf.Tensor, labels: tf.Tensor) -> Tuple[tf.Tensor, tf.Tensor]:
num_sampled = tf.minimum(self._num_hard_negatives + 1, tf.shape(logits)[1])
_, indices = tf.nn.top_k(logits + labels * MAX_FLOAT, k=num_sampled, sorted=False)
logits = _gather_elements_along_row(logits, indices)
labels = _gather_elements_along_row(labels, indices)
return logits, labels
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.