LMCost   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 7
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 7
rs 10
c 1
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 5 1
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]))