tensorflow / tensorflow/recommenders
load_weights can't work
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2k
- Forks
- 300
- PR merge metrics
- No merged PRs in 30d
Description
session 1.
def build_model():
model = RetrievalModel(item_model, user_model)
learning_rate = 0.01
model.compile(optimizer=tf.keras.optimizers.Adagrad(learning_rate))
return model
model = build_model()
model.fit(behavior_dataset, epochs=30)
model.save_weights(save_path,overwrite=True )
compute_loss_args = {
"user_id" : tf.constant(["45"]),
"work_id" : tf.constant(["45"]),
"tags" : tf.constant([""]),
"work_uid" : tf.constant(["45"]),
"money_goods" : tf.constant([100]),
"category_id" : tf.constant(["2"]),
"bid_type" : tf.constant(["normal"]),
"is_rec" : tf.constant(["1"]),
"weights" : tf.constant([1]),
}
model(compute_loss_args)
s = model.load_weights(save_path ).expect_partial()
k = 100
user_id = '1035369'
index = tfrs.layers.factorized_top_k.BruteForce(model.user_model,k)
index.index_from_dataset(
work_dataset.shuffle(100_100).map(lambda x: (x["work_id"], model.item_model(x))) #注意,这里是全局可推荐列表
)
print(f"rec user_id :{user_id}")
print(user_id in unique_user_id)
is right。
session 2:
def build_model():
model = RetrievalModel(item_model, user_model)
learning_rate = 0.01
model.compile(optimizer=tf.keras.optimizers.Adagrad(learning_rate))
return model
- _model = build_model() #delete
- model.fit(behavior_dataset, epochs=30) #delete
- model.save_weights(save_path,overwrite=True )#delete_
compute_loss_args = {
"user_id" : tf.constant(["45"]),
"work_id" : tf.constant(["45"]),
"tags" : tf.constant([""]),
"work_uid" : tf.constant(["45"]),
"money_goods" : tf.constant([100]),
"category_id" : tf.constant(["2"]),
"bid_type" : tf.constant(["normal"]),
"is_rec" : tf.constant(["1"]),
"weights" : tf.constant([1]),
}
model(compute_loss_args)
s = model.load_weights(save_path ).expect_partial()
k = 100
user_id = '1035369'
index = tfrs.layers.factorized_top_k.BruteForce(model.user_model,k)
index.index_from_dataset(
work_dataset.shuffle(100_100).map(lambda x: (x["work_id"], model.item_model(x))) #注意,这里是全局可推荐列表
)
print(f"rec user_id :{user_id}")
print(user_id in unique_user_id)
is wrong 不准确。
tensorboard 2.15.2
keras 2.15.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the two sessions around build_model(), model.fit(), save_weights(), model(compute_loss_args), and load_weights(). Compare the resulting recommendation output and confirm whether the issue is weight restoration or model initialization; done means the cause is isolated and the expected behavior is documented with a minimal reproducible example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- keras, python, tensorflow
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100