TF·IDF 重要词 假如一个词在某类文本(假设为A类)中出现次数很多,而在其他类别文本出现很少,那么这个词是A类文本的重要词。 反之,如果一个词出现在很多领域,则其对于任意类别的重要性都很差。...数学表示 一种NLP经典统计值:TF·IDF TF:词频 某个词在某类别中出现的次数 / 该类别词总数 IDF:逆文档频率 \log\left(\frac{\text{语料库的文档总数}}{\text{...TF·IDF的优势 可解释性好 可以清晰看到关键词 即使预测出错,也很容易找到原因 计算速度快 对于标注数据依赖小 可以使用无标注语料完成一部分工作 可以与很多算法组合使用 可以看作是词权重 TFIDF
==因此,tensorflow中用tf.Variable(),tf.get_variable(),tf.Variable_scope(),tf.name_scope()几个函数来实现:== ---- 一...、tf.Variable(),tf.get_variable()的作用与区别: tf.Variable()和tf.get_variable()都是用于在一个name_scope下面获取或创建一个变量的两种方式...二、tf.name_scope()与tf.variable_scope()的作用与区别: tf.name_scope():主要用于管理一个图里面的各种op,返回的是一个以scope_name命名的context...import tensorflow as tf with tf.name_scope('name_scope_x'): var1 = tf.get_variable(name='var1',...shape=[1], dtype=tf.float32) var3 = tf.Variable(name='var2', initial_value=[2], dtype=tf.float32)
语音识别准确率高、用于会议内容转写、客服质检等场景,助力企业将本增效
x=tf.ones([2,3]) tf.norm(x,ord=1) tf.norm(x,ord=2) tf.norm(x,ord=np.inf) # 无穷 最大/最小、均值、和 函数 作用 tf.reduce_max...最大 tf.reduce_min 最小 tf.reduce.mean 均值 tf.reduce_sum 和 上述的函数都可以指定axis;如果不指定,tf.reduce_....tf.tile()函数实现长度为1的维度复制的功能;tf.tile() 函数可以在任意维度将数据重复复制多份 x = tf.random.normal([4,32,32,3]) tf.tile(x,...[2,3,3,1]) 数据限幅 tf.maximum()实现下限幅 tf.minimum()实现上限幅 tf.clip_by_vlaue实现双边限幅 x = tf.range(9) tf.maximum...索引从0开始 x = tf.random.uniform([4,35,8],maxval=100,dtype=tf.int32) tf.gather(x, [0,1], axis=0) tf.gather
(np.random.randn(3,2))#c=tf.matmul(a,b)c=tf.multiply(a,b)init=tf.global_variables_initializer()with tf.Session...而tf.matmul()表示普通的矩阵乘法。而且tf.multiply(a,b)和tf.matmul(a,b)都要求a和b的类型必须一致。但是之间存在着细微的区别。...)b=np.float32(np.random.randn(3,2))c=tf.matmul(a,b)#c=tf.multiply(a,b)init=tf.global_variables_initializer...(a,b)#c=tf.multiply(a,b)init=tf.global_variables_initializer()with tf.Session() as sess: print (type...b=tf.constant([[1, 2, 3],[4, 5, 6]], dtype=np.int32)#c=tf.matmul(a,b)c=tf.multiply(a,b)init=tf.global_variables_initializer
1.tf.multiply()两个矩阵中对应元素各自相乘 格式: tf.multiply(x, y, name=None) 参数: x: 一个类型为:half, float32, float64...2.tf.matmul()将矩阵a乘以矩阵b,生成a * b。...#两个矩阵对应元素各自相乘 x=tf.constant([[1.,2.,3.],[1.,2.,3.],[1.,2.,3.]]) y=tf.constant([[0.,0.,1.],[0.,0.,1....#注意这里x,y必须要有相同的数据类型,不然就会因为数据类型不匹配报错 z=tf.multiply(x,y) #两个数相乘 x1=tf.constant(1) y1=tf.constant(2) #注意这里...=tf.constant([[1.,2.,3.],[1.,2.,3.],[1.,2.,3.]]) y3=tf.constant([[0.,0.,1.],[0.,0.,1.],[0.,0.,1.]])
tf.math.greater_equal( x, y, name=None)返回元素的真值(x >= y)。参数:x: 张量。...原链接: https://tensorflow.google.cn/versions/r1.14/api_docs/python/tf/math/greater_equal
if mode == tf.estimator.ModeKeys.PREDICT: final_input = tf.map_fn(lambda im_tf: tf.image.central_crop...= tf.map_fn(lambda im_tf: tf.image.random_flip_left_right(im_tf), input_layer) final_input =...tf.map_fn(lambda im_tf: tf.random_crop(im_tf, size=[224,224,3]), final_input) tf.summary.image...tf.cast(image_decoded, tf.float32) image = tf.image.resize_images(image, [224, 224]) # (2) return...(images) labels = tf.constant(labels) images = tf.random_shuffle(images, seed=0) labels = tf.random_shuffle
MachineLP的Github(欢迎follow):https://github.com/MachineLP tf.estimator 是Tensorflow的高级API, 可快速训练和评估各种传统机器学习模型...import os from six.moves.urllib.request import urlopen import numpy as np import tensorflow as tf #...training_set = tf.contrib.learn.datasets.base.load_csv_with_header( filename=IRIS_TRAINING,...target_dtype=np.int, features_dtype=np.float32) test_set = tf.contrib.learn.datasets.base.load_csv_with_header...classifier = tf.estimator.DNNClassifier(feature_columns=feature_columns,
tf.Session():需要在启动session之前构建整个计算图,然后启动该计算图。...对比一下: import tensorflow as tf import numpy as np a=tf.constant([[1., 2., 3.],[4., 5., 6.]]) b=np.float32...(np.random.randn(3,2)) c=tf.matmul(a,b) init=tf.global_variables_initializer() sess=tf.Session() print...()就不会出错,说白了InteractiveSession()相当于: sess=tf.Session() with sess.as_default(): 换句话说,如果说想让sess=tf.Session...(np.random.randn(3,2)) c=tf.matmul(a,b) init=tf.global_variables_initializer() with tf.Session() as sess
我们在使用tensorflow时,会发现tf.nn,tf.layers, tf.contrib模块有很多功能是重复的,尤其是卷积操作,在使用的时候,我们可以根据需要现在不同的模块。...下面是对三个模块的简述: (1)tf.nn :提供神经网络相关操作的支持,包括卷积操作(conv)、池化操作(pooling)、归一化、loss、分类操作、embedding、RNN、Evaluation...(2)tf.layers:主要提供的高层的神经网络,主要和卷积相关的,个人感觉是对tf.nn的进一步封装,tf.nn会更底层一些。 ...(3)tf.contrib:tf.contrib.layers提供够将计算图中的 网络层、正则化、摘要操作、是构建计算图的高级操作,但是tf.contrib包含不稳定和实验代码,有可能以后API会改变
tf.math.maximum tf.math.maximum( x, y, name=None ) 此函数返回x和y的最大值(即x > y ?x: y)。...tf.math.minimum tf.math.minimum( x, y, name=None ) 返回x和y的最小值(即x < y ?x: y)。 参数: x: 张量。...原链接: https://tensorflow.google.cn/versions/r1.11/api_docs/python/tf/math/maximum?...hl=en https://tensorflow.google.cn/versions/r1.11/api_docs/python/tf/math/minimum?hl=en
一、tf.reverse()tf.reverse( tensor, axis, name=None)参数:tensor: 需要进行反转的张量,类型必须为其中的一个uint8, int8...(A,perm=[0,2,1,3])Y = tf.reverse(X,axis=[1]) with tf.Session() as sess: print("A") print(A)...])Y=tf.transpose(A,[1,0,2])with tf.Session() as sess: print("original:") print(A) print("transpose...,[0,2,1])Y=tf.transpose(A,[1,0,2])with tf.Session() as sess: print("A[1][1][0]:") print(A[1][1][0...(A,[0,2,1,3])Y=tf.transpose(A,[1,0,3,2]) with tf.Session() as sess: print("A") print(A) print
别名:tf.RaggedTensor.__pow__tf.compat.v1.RaggedTensor....__pow__tf.compat.v1.math.powtf.compat.v1.powtf.compat.v2.RaggedTensor....__pow__tf.compat.v2.math.powtf.compat.v2.powtf.math.powtf.powtf.math.pow( x, y, name=None)给定一个张量...例如:x = tf.constant([[2, 2], [3, 3]])y = tf.constant([[8, 16], [2, 3]])tf.pow(x, y) # [[256, 65536],
TensorFlow tf.app&tf.app.flags用法介绍 TensorFlow tf.app argparse tf.app.flags 下面介绍 tf.app.flags.FLAGS的使用... ---- ---- FLAGS = tf.app.flags.FLAGS ---- ---- # tf.app.flags.DEFINE_string("param_name", "default_val...per query") ---- tf.app.flags.DEFINE_integer("embedding_size", 50, "embedding size") ---- ---- tf.app.flags.DEFINE_float...tf.app.run() 该函数一般都是出现在这种代码中: if __name__ == '__main__': ---- tf.app.run() ---- 上述第一行代码表示如果当前是从其它模块调用的该模块程序...---- 参考: TensorFlow 中 tf.app.flags.FLAGS 的用法介绍 Deep Learning学习笔记(六)详解tf.app.flags()和tf.app.run()的源码
()/tf.random.categorical()用法解析 tf.multinomial()在tensorflow2.0版本已经被移除,取而代之的就是tf.random.categorical() tf.random.categorical...import tensorflow as tf; for i in tf.range(10): samples = tf.random.categorical([[1.0,1.0,1.0,1.0,4.0...常用的是tf.float32,tf.float64等数值类型 shape:数据形状。...demo: import tensorflow as tf import numpy as np # 定义placeholder input1 = tf.placeholder(tf.float32)...input2 = tf.placeholder(tf.float32) # 定义乘法运算 output = tf.multiply(input1, input2) # 通过session执行乘法运行
# python形式 b = tf.constant(2.0) # 这才是TF形式 c = tf.constant([1,2.0,3.7]) tf.is_true(b) # True 返回值中几个具体信息...tf.int16/32/64 tf.float16/32/64;tf.float64就是tf.double 需要注意的点: 高精度转低精度可能会报错 对于浮点数,高精度的张量可以表示更精准的数据 实际中...,一般使用tf.int32和tf.float32 import numpy as np import tensorflow as tf # 创建张量的时候指定精度 tf.constant(12345678..., dtype=tf.int32) tf.constant(np.pi, dtype=tf.float64) 通过张量的dtype属性可以获取张量的精度 类型转换 通过tf.cast函数进行转换,需要注意的地方...() tf.zeros()/tf.zeros_like() tf.ones([2,3]) a = tf.zeros([2,4]) b = tf.ones_like(a) # 形状相同 自定义数值张量
,dtype=tf.float32)))返回5*5的矩阵,产生于low和high之间,产生的值是均匀分布的。...例如: import tensorflow as tf import numpy as np with tf.Session() as sess: print(sess.run(tf.random_uniform...tf.truncated_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None) 从截断的正态分布中输出随机值...代码 a = tf.Variable(tf.random_normal([2,2],seed=1)) b = tf.Variable(tf.truncated_normal([2,2],seed=2))...c = tf.truncated_normal(shape=[10,10], mean=0, stddev=1) init = tf.global_variables_initializer() with
tf.variable_scope可以让变量有相同的命名,包括tf.get_variable得到的变量,还有tf.Variable的变量 tf.name_scope可以让变量有相同的命名,只是限于tf.Variable...('V1'): a1 = tf.get_variable(name='a1', shape=[1], initializer=tf.constant_initializer(1)) a2 = tf.Variable...(name='a1', shape=[1], initializer=tf.constant_initializer(1)) a4 = tf.Variable(tf.random_normal(shape...(name='a1', shape=[1], initializer=tf.constant_initializer(1)) a2 = tf.Variable(tf.random_normal(shape...=[1], initializer=tf.constant_initializer(1)) a4 = tf.Variable(tf.random_normal(shape=[2,3], mean=0,
tf.nn.relu()函数 tf.nn.relu()函数是将大于0的数保持不变,小于0的数置为0 import tensorflow as tf a = tf.constant([-2,-1,0,2,3...tf a = tf.constant([[-2,-4],[4,-2]]) with tf.Session() as sess: print(sess.run(tf.nn.relu(a))) 输出结果为...import tensorflow as tf a=tf.constant([[1,1],[2,2],[3,3]],dtype=tf.float32) b=tf.constant([1,-1],dtype...=tf.float32) c=tf.constant([1],dtype=tf.float32) with tf.Session() as sess: print('bias_add:')...(x,y) x1=tf.constant(1) y1=tf.constant(2) z1=tf.add(x1,y1) x2=tf.constant(2) y2=tf.constant
tf.math.abs( x, name=None)计算张量的绝对值。给定一个整数或浮点值的张量,这个操作返回一个相同类型的张量,其中每个元素都包含输入中相应元素的绝对值。...例如:x = tf.constant([[-2.25 + 4.75j], [-3.25 + 5.75j]])tf.abs(x) # [5.25594902, 6.60492229]参数:x: 一个类型为...如果x是稀疏张量,返回SparseTensor(x.indices,tf.math.abs (x.value,…),x.dense_shape)。...原链接: https://tensorflow.google.cn/versions/r1.14/api_docs/python/tf/math/abs