LMCost.get()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
dl 0
loc 5
rs 9.4285
c 1
b 0
f 0
1
#!/usr/bin/env python
2
# -*- coding: utf-8 -*-
3
4
from deepy.core.env import EPSILON
5
from deepy.core import CrossEntropyCost
6
import theano.tensor as T
7
8
class LMCost(CrossEntropyCost):
9
10
    def get(self):
11
        y = T.clip(self.result_tensor, EPSILON, 1.0 - EPSILON)
12
        y = y.reshape((-1, y.shape[-1]))
13
        k = self.index_tensor.reshape((-1,))
14
        return -T.mean(T.log2(y[T.arange(k.shape[0]), k]))