本期分析Senta中的评估标准Metric
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import time
import numpy as np
from scipy.stats import pearsonr, spearmanr
from six.moves import xrange
import paddle.fluid as fluid
from functools import partial
def scale_l2(x, norm_length):
"""
# copy lines from here https://github.com/tensorflow/models/blob/master/research/adversarial_text/adversarial_losses.py#L190
# shape(x) = (batch, num_timesteps, d)
# Divide x by max(abs(x)) for a numerically stable L2 norm.
# 2norm(x) = a * 2norm(x/a)
# Scale over the full sequence, dims (1, 2)
"""
alpha = fluid.layers.reduce_max(fluid.layers.abs(x), dim=1, keep_dim=True) + 1e-12
l2_norm = alpha