Savvy在英国
2020-08-28 01:56
采纳率: 33.3%
浏览 123

请帮我将这段代码转成python格式

python初学者,需要的一个模型是scala格式,如何转成python,请大家帮助。

// subsampling the words : refer to Google's word2vec NIPS paper to understand this
//
if (sample > 0)
sen = sen.filter(id => subSample(id) != -1)

val senLength = sen.size
for (senPosition <- 0 until senLength) {
  val currWord = sen(senPosition)

  //
  // dynamic window-size as in word2vec. 
  //
  val b =  rng.nextInt(window)
 // make the contexts
      //
      val contexts = new mutable.ArrayBuffer[Int]
      for (a <- b until window * 2 + 1 - b) if (a != window) {
        val c = senPosition - window + a
        if (c >= 0 && c < senLength)
          contexts += sen(c)
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新