自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(65)
  • 资源 (1)
  • 收藏
  • 关注

原创 leetcode-链表操作

反转部分反转删除重复元素删除倒数第k个节点环形链表环形链表入口相交链表

2021-12-16 10:27:02 409

原创 leetcode-第k大的数、最小的k个数

剑指 Offer 40. 最小的k个数class Solution: def getLeastNumbers(self, arr: List[int], k: int) -> List[int]: def partition(arr, l, r): #选定中值 pivotvalue = arr[l] lmark = l + 1 rmark = r done

2021-12-15 16:39:33 570

原创 leetcode--矩阵遍历与搜索

54. 螺旋矩阵class Solution(object): def spiralOrder(self, matrix): res = [] row, col= len(matrix)-1, len(matrix[0])-1 i, j = 0, 0 while i<=row and j <=col: if i == row: for x in range(j, c

2021-12-15 12:42:27 267

原创 leetcode-二叉搜索树先关题目

653. 两数之和 IV - 输入 BSTclass Solution(object): def findTarget(self, root, k): def inorder(node): if not node: return [] return inorder(node.left) + [node.val] + inorder(node.right) alist =

2021-12-14 21:24:38 314

原创 leetcode-零钱问题

无限放取+方法数arr里都是正数,没有重复,每一个值代表一种货币,每一种都可以用无限张,最终要找零钱是aim,找零方法数放回递归 入参 process(arr, index, rest)自由使用arr[index…] 所有的面值需要搞定的钱数rest返回找零的方法数终止条件,决定dp表的一些初始位置,非常重要if index == arr.length: resturn rest == 1 if rest==0 else 0递归方程way = 0zhang = 0while

2021-12-14 11:37:37 233

原创 leetcode-同事总结的热门代码题

最大公共子序列最大公共子串最长递增子序列最长递增子串连续子数组的最大和连续子数组的最大乘积最长回文子串子数组和为k连续子数组和为k

2021-12-14 09:24:05 65

原创 leetcode-旋转数组相关题目解答

33. 搜索旋转排序数组153. 寻找旋转排序数组中的最小值154. 寻找旋转排序数组中的最小值 II[]

2021-12-13 17:44:15 301

原创 leetcode之两、三、四、最近接之和题目

1. 两数之和class Solution(object): def twoSum(self, nums, target): d = {} for i in range(len(nums)): diff = target - nums[i] if diff in d: return [i, d[diff]] d[nums[i]] = i

2021-12-13 14:57:06 287

原创 leetcode-合并有序数组、链表系列题目解法总结

展示内容:一次遍历 将结果输出、而不是判断大小、再做其他冗余处理88题 合并两个有序数组版本一class Solution: def merge(self , A, m, B, n): if n ==0: return A if m ==0: A[:] = B[:] return A total, m, n = m+n-1, m-1, n-1 while m>=0 or n&

2021-12-12 19:55:09 182

原创 tf estimator debug

How to print tensor in Tensorflow custom estimator for debugging?

2021-10-21 13:39:35 163

原创 tf.newaxis vs tf.expand_dims

There is no real difference between the three, but sometimes one or the other may be more convenient:What’s the difference between using tf.expand_dims and tf.newaxis in Tensorflow?

2021-09-15 13:20:29 128

原创 afm_layer

# coding=utf-8import itertoolsimport tensorflow as tffrom tensorflow.keras import Modelfrom tensorflow.keras.regularizers import l2from tensorflow.keras.layers import Embedding, Dense, Dropout, Inputfrom tensorflow.keras.layers import Layerclass .

2021-09-11 12:39:39 70

原创 CIN_layer

#coding=utf-8import tensorflow as tffrom tensorflow.python.keras.layers import Concatenate,Conv1D,Reshape## 只计算其中一层交叉的结果def compressed_interaction_net(x0, xl, D, n_filters): """ @param x0: 原始输入 @param xl: 第l层的输入 @param D: embedding d.

2021-09-11 11:03:45 115

原创 deep_cross_layer

#coding=utf-8import tensorflow as tffrom tensorflow.keras.layers import Dense, ReLU, Layerclass DeepCrossLater(Layer): def __init__(self,dim_stack, name=None): """ :param hidden_unit: A list. Neural network hidden units. :pa

2021-09-10 18:49:49 78

原创 tf-矩阵相关知识

1、向量 or 矩阵 # 向量(3,) v1 = tf.constant([ 1, 2, 3]) print(v1.shape) ## 矩阵(3, 1) v2 = tf.constant([ [1], [2], [3]]) print(v2.shape)2、最后一维升维 ## 矩阵最后一维增加维度 q = tf.constant([ [ 1, 2, 3],

2021-09-06 17:23:28 413

原创 机器学习概念理解(持续更新)

Q:模型优化的直接目标为什么是lossA:loss 是由损失函数决定的,损失函数定义了真实值与预测值之间的差距 loss代表了模型对数据拟合的程度,loss越小,说明模型对数据拟合得越好

2021-09-03 12:54:07 75

原创 nc 跨机房传输文件

本地机器: nc -l 7001 > filename.zip远端机器:nc 192.168.17.223 10013 < filename.zip

2021-08-31 11:23:15 98

原创 tf keras 训练过程简述

持续更新。。。。。。。

2021-08-27 11:31:29 139

原创 tf.keras.layer介绍

通过继承tf.keras.layer实现自定义层的最佳方法是继承tf.keras.Layer类并实现:init ,在其中进行所有与输入无关的变量或常量的初始化build,在其中知道输入张量的形状,并可以进行其余的初始化call,在这里进行前向传播逻辑的计算的定义请注意,不必等到build被调用才创建变量,也可以在__init__中直接定义。但是,在build中创建变量的好处在于,可以根据build的参数 input shape来自动调整变量的shape。而在__init__中创建变量意味着需要显

2021-08-25 13:52:59 490

原创 tf2.x函数签名

一般说法:input_signature的好处:1.可以限定函数的输入类型,以防止调用函数时调错,2.一个函数有了input_signature之后,在tensorflow里边才可以保存成savedmodel。在保存成savedmodel的过程中,需要使用get_concrete_function函数把一个tf.function标注的普通的python函数变成带有图定义的函数。使用经验:当一个函数被@tf.function 比较后,可以使用get_concrete_function 然后传入原函数

2021-08-25 11:28:15 287

原创 kernel_regularizerand Activity regularizers

#coding=utf-8import tensorflow as tflayer = tf.keras.layers.Dense(units=5, kernel_initializer='ones', kernel_regularizer=tf.keras.regularizers.l1_l2(l1=0.01, l2=0.01))tensor = tf.ones(shape=

2021-08-24 20:02:58 313

原创 tf.clip_by_global_norm函数解析

#coding=utf-8import tensorflow as tfimport numpy as npdef test_clip_by_global_norm(): x = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0] r, use_norm = tf.clip_by_global_norm(x, 10) print(r,use_norm) #--------use_norm---------- x_l2 = np.ar

2021-08-24 14:20:08 255

原创 tf-estimator学习笔记

持续更新。。。estimator 对标的是tf.keras.Model 模型级别的抽象 ,我觉得这个和module应该是一个级别的,因为每个Estimater的核心是模型函数,一种为训练、预估和预测构建计算图的方法,module实例化的对象也是包含训练、预估和导出...

2021-08-24 12:02:16 105

原创 mmoe_layer

#!usr/bin/env python# coding=utf-8import numpy as npimport pandas as pdimport datetimeimport itertoolsimport tensorflow as tffrom tensorflow.keras.layers import *import tensorflow.keras.backend as Kfrom tensorflow.keras import layersclass MMoEL

2021-08-06 13:30:04 122

原创 What is a nested structure in TensorFlow?

指的是tuple或者dictProviding answer here from the comment section for the benefit of the community.Nested Structure in TensorFlow generally refers to a tuple or a dict containing tensor values, or other nested structures.The typical case is a dataset where e

2021-08-05 11:26:25 343

原创 tf.add_weight 和 tf.Variable使用例子

class Linear(keras.layers.Layer): def __init__(self, units=32, input_dim=32): super(Linear, self).__init__() w_init = tf.random_normal_initializer() self.w = tf.Variable( initial_value=w_init(shape=(input_dim, units)

2021-07-21 18:28:45 4549

原创 tf.compat.v1.sparse_to_dense

import tensorflow as tfmulti_one_hot = tf.sparse.SparseTensor(indices=[[0, 0], [0, 1], [2, 0], [4, 0], [4, 1], [4, 2], [4, 3]],

2021-05-23 15:56:31 206

原创 tf.nn.embedding_lookup

tf.nn.embedding_lookup( params, ids, partition_strategy='mod', name=None, validate_indices=True, max_norm=None)作用:在params表中按照ids查询向量。params是一个词表,大小为NH,N为词的数量,H为词向量维度的大小。图中的params大小为310,表示有3个词,每个词有10维。一句话中有四个词,对应的id为0,2,0,1,按照ids在

2021-05-23 15:21:42 89

原创 scale_dot_product_attention and multi_head_attention tf2.x

import matplotlib as mplimport numpy as npimport sklearnimport pandas as pdimport osimport sysimport timeimport tensorflow as tffrom tensorflow import kerasprint(tf.__version__)print(sys.version_info)for module in mpl, np, pd, sklearn, tf, ker

2021-05-11 11:40:20 395

原创 tf 维度变化 汇总

tf.reduce_mean(input_tensor, axis=None, keep_dims=False, name=None, reduction_indices=None)Computes the mean of elements across dimensions of a tensor.Reduces input_tensor along the dimensions given in axis. Unless keep_dims is true, the rank of the ten

2021-05-09 21:07:14 91

原创 测试数据生成

import matplotlib as mplimport numpy as npimport sklearnimport pandas as pdimport osimport sysimport timeimport tensorflow as tffrom tensorflow import kerasprint(tf.__version__)print(sys.version_info)for module in mpl, np, pd, sklearn, tf, ker

2021-05-08 15:59:49 136

原创 python-list处理例子

a = [(1,2), (3, 4), (5, 6)]c, d = zip(*a)print(c, d)(1, 3, 5) (2, 4, 6)

2021-05-08 14:52:26 61

原创 unicodedata 字符处理例子

>>> import unicodedata>>> import sys>>> cmb_chrs = dict.fromkeys(c for c in range(sys.maxunicode)... if unicodedata.combining(chr(c)))...>>> b = unicodedata.normalize('NFD', a)>>> b

2021-05-08 14:51:05 290

原创 TF乘法之multiply、matmul、*

import tensorflow as tfw = tf.Variable([[0.4], [1.2]], dtype=tf.float32) # w.shape: [2, 1]x = tf.Variable([range(1,6), range(5,10)], dtype=tf.float32) # x.shape: [2, 5]y = w * x # 等同于 y = tf.multiply(w, x) y.shape: [2, 5]sess = tf.Session()ini

2021-05-08 11:31:31 1128 1

原创 tensorflow交叉熵损失函数-cross_entropy_with_logits 在库函数中比较

tf.nn.softmax(logits,axis=None,name=None,dim=None)作用:softmax函数的作用就是归一化。输入: 全连接层(往往是模型的最后一层)的值,一般代码中叫做logits输出: 归一化的值,含义是属于该位置的概率,一般代码叫做probs。例如输入[0.4,0.1,0.2,0.3],那么这个样本最可能属于第0个位置,也就是第0类。这是由于logits的维度大小就设定的是任务的类别,所以第0个位置就代表第0类。softmax函数的输出不改变维度的大小。

2021-05-08 10:23:11 451

原创 tf.where()用法

where(condition, x=None, y=None, name=None)的用法condition, x, y 相同维度,condition是bool型值,True/False返回值是对应元素,condition中元素为True的元素替换为x中的元素,为False的元素替换为y中对应元素x只负责对应替换True的元素,y只负责对应替换False的元素,x,y各有分工由于是替换,返回值的维度,和condition,x , y都是相等的。看个例子:import tensorflow a

2021-05-07 19:46:46 221

原创 tf.ones_like()

tf.ones_like( input, dtype=None, name=None)import tensorflow as tfimport numpy as np# 生成一个tensor,内部数据随机产生a = tf.convert_to_tensor(np.random.random([2, 4, 5]), dtype=tf.float32)# ones_likeb = tf.ones_like(a, dtype=tf.float32, name='ones_like'

2021-05-07 18:07:51 128

原创 numpy相关

np.random.randint(2, size=10)array([1, 0, 0, 0, 1, 1, 0, 0, 1, 0]) # randomnp.random.randint(1, size=10)array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])numpy.random.randint¶

2021-05-07 14:27:47 64

原创 tf.cast()和 tf.tile()

tf.cast()数据类型转换tensorflow 中tile函数用法讲解

2021-05-07 14:06:23 81

原创 tf.SparseTensor和tf.sparse_tensor_to_dense

import tensorflow as tfimport numpy as npindices = np.array([[0, 0], [1, 1], [2, 2], [3, 4]], dtype=np.int32)values = np.array([1, 2, 3, 4], dtype=np.int32)shape = np.array([5, 5], dtype=np.int32)x = tf.SparseTensor(values=values,indices=indices,dens

2021-05-07 12:12:32 989 1

在线学习最优化求解.pdf

在线学习方法总结,在推荐系统中通过样本快照 结合在线学习的方式,能让模型具有很好的捕捉用户即时兴趣的能力 , 本文章对不同人群有不同的定位方式,重点是FTRL

2020-06-21

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除