Skip to content

Commit

Permalink
Merge pull request wzhe06#31 from happy-yuxuan/bugfix
Browse files Browse the repository at this point in the history
fix bug of generating user emb
  • Loading branch information
wzhe06 authored Feb 26, 2021
2 parents 5e27025 + 3eed2f6 commit ec50fa3
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,17 @@ object Embedding {
val userId = user._1
var userEmb = new Array[Float](embLength)

var movieCount = 0
userEmb = user._2.foldRight[Array[Float]](userEmb)((row, newEmb) => {
val movieId = row.getAs[String]("movieId")
val movieEmb = word2VecModel.getVectors.get(movieId)
movieCount += 1
if(movieEmb.isDefined){
newEmb.zip(movieEmb.get).map { case (x, y) => x + y }
}else{
newEmb
}
})
}).map((x: Float) => x / movieCount)
userEmbeddings.append((userId,userEmb))
})

Expand Down

0 comments on commit ec50fa3

Please sign in to comment.