小编Mar*_*ruf的帖子

训练破坏了ResourceExausted错误

我是tensorflow和机器学习的新手.最近我正在研究一个模型.我的模型如下,

  1. 字符级嵌入向量 - >嵌入查找 - > LSTM1

  2. 字级嵌入矢量 - >嵌入查找 - > LSTM2

  3. [LSTM1 + LSTM2] - >单层MLP-> softmax层

  4. [LSTM1 + LSTM2] - >单层MLP-> WGAN鉴别器

  5. 他的模型代码

当我正在研究这个模型时,我得到了以下错误.我以为我的批次太大了.因此,我尝试将批量大小从20减少到10,但它不起作用.

ResourceExhaustedError(参见上面的回溯):OOM在分配张量形状时[24760,100] [[节点:字符/ bidirectional_rnn/bw/bw/while/bw/lstm_cell/split = Split [T = DT_FLOAT,num_split = 4,_device] ="/ job:localhost/replica:0/task:0/device:GPU:0"](gradients_2/Add_3/y,chars/bidirectional_rnn/bw/bw/while/bw/lstm_cell/BiasAdd)] [[Node :bi-lstm/bidirectional_rnn/bw/bw/stack/_167 = _Recvclient_terminated = false,recv_device ="/ job:localhost/replica:0/task:0/device:CPU:0",send_device ="/ job:localhost /副本:0 /任务:0 /设备:GPU:0",send_device_incarnation = 1,tensor_name ="edge_636_bi-lstm/bidirectional_rnn/bw/bw/stack",tensor_type = DT_INT32,_device ="/ job:localhost/replica:0 /任务:0 /装置:CPU:0" ]]

张量形状[24760,100]表示2476000*32/8*1024*1024 = 9.44519043 MB内存.我在Titan X(11 GB)GPU上运行代码.怎么可能出错?为什么会发生这种错误?

*额外信息*:LSTM1的大小为100.对于双向LSTM,它变为200.LSTM2的大小为300.对于双向LSTM,它变为600.

*注*:错误发生在32个纪元之后.我的问题是为什么在32个时代之后出现了错误.为什么不在最初的时代.

python batch-processing tensorflow

13
推荐指数
1
解决办法
1919
查看次数

PEP8警告:连续行缺少缩进或缩进

我使用的pycharm是我真正喜欢整合PEP8警告的位置,它可以帮助我编写简洁的python代码。

通常当我有多个返回类型时,function我在多行中使用返回变量,如下所示,

raw_data,\
t_raw_data,\                      #warning in t_raw_data
words_info,\                      #warning in words_info
t_words_info,\                    #warning in t_words_info
tags_info,\                       #warning in tags_info
char_info,\                       #warning in char_info
t_char_info = preprocess(param)   #warning in t_char_info
Run Code Online (Sandbox Code Playgroud)

给我警告

PEP 8: continuation line missing indentation or outdented
Run Code Online (Sandbox Code Playgroud)

那么,接收多个返回值的最佳实践是什么。是什么pythonic方式。我来自C++背景,对这种pythonic方式我很陌生。

注意:如果我发布以下代码,则没有PEP8警告,但这似乎很奇怪。

raw_data,\
    t_raw_data,\
    words_info,\
    t_words_info,\
    tags_info,\
    char_info,\
    t_char_info = preprocess(param)
Run Code Online (Sandbox Code Playgroud)

pep8 python-3.x

5
推荐指数
1
解决办法
1239
查看次数

预训练的skip-gram和skip-n-gram向量

我正在做一个项目,我需要一个预训练的skip-gram模型向量.我听说还有一个名为skip-n-gram模型的变体可以提供更好的结果.

我想知道我自己需要训练什么样的模型?因为我只需要它们来为我的模型初始化嵌入层.

我搜索得足够多但没有得到很好的例子.我需要你的建议.我在哪里可以获得这种预先训练过的模型,或者没有预先训练好的模型.

word2vec pre-trained-model

3
推荐指数
1
解决办法
720
查看次数

使用RSA算法加密 - 字母'w','x','y','z'

我一直在为RSA算法编写代码.它运作良好,但不幸的是它显示了小'w','z','x','y'的错误答案.

我的加密算法很简单.使用两个不同的素数和'e'我生成公钥,然后通过生成'd'我创建了私钥.然后使用BIGMOD(快速取幂)算法,我只计算模数部分进行加密和解密.这是我的代码:

#include<stdio.h>
#include<string.h>

long long int square(long long int a);
long long int BigMod(int M,int E,int N);
void encrypt(int l,int E,int N);
void decrypt(int E,int N );

int main()
{
    main_RSA();
    return 0;
}

void main_RSA()
{

    int p,q;
    printf("Write two distinct Prime number separated by space:");
    scanf("%d %d",&p,&q);
    int n=p*q;
    int phi=(p-1)*(q-1);
    int e;
    printf("Enter a prime number 'e' as GCD(e,(P-1)*(Q-1)) : ");
    scanf("%d",&e);
    printf("public key( e , n ) : ( %d %d )\n",e,n);
    int d,RES=-1;
    for(d=1;;d++){ …
Run Code Online (Sandbox Code Playgroud)

c encryption cryptography rsa

2
推荐指数
1
解决办法
5903
查看次数

为什么Vector不会排序?

我在oj上解决了一个问题.但突然间我发现这vector<char*>不符合我的目的.我究竟做错了什么?如果有人能让我明白这个问题......问题描述很简单,你只需要从输入文件中取出并对其进行排序.这是我所做的,但它不会排序:

vector<char*>V;
char str[501][201];
int l=0;
char str1[]= {'~','.','\n','\r',' ','!','@','#','$','%','^','&','*','(',')','+','-','_','=','{','}','[',']',':',';','"','<','>','?','/','|'};
while(gets(str[l++]))
{

    for(int i=0; str[l-1][i]; i++)
    {
        if(str[l-1][i]>='A' && str[l-1][i]<='Z')str[l-1][i]=str[l-1][i]-'A'+'a';
    }
    char *pch;
    pch=strtok(str[l-1],str1);
    while(pch!=NULL)
    {
        // printf("%s\n",pch);
        V.push_back(pch);
        pch=strtok(NULL,str1);
    }
}

sort(V.begin(),V.end());

for(vector<char*>::iterator it=V.begin(); it!=V.end(); it++)
    cout<<*it<<endl;
Run Code Online (Sandbox Code Playgroud)

c++ sorting vector

0
推荐指数
1
解决办法
161
查看次数

"Console ::"不编译

此代码取自http://msdn.microsoft.com/en-us/library/system.console.windowwidth.aspx 我想在gcc编译器中编译它.

#include<cstdio>
#include<string>
#include<windows.h>
#include<iostream>
using namespace System;
int main()
{
   int origWidth;
   int width;
   int origHeight;
   int height;
   String^ m1 = "The current window width is {0}, and the " 
   "current window height is {1}.";
   String^ m2 = "The new window width is {0}, and the new " 
   "window height is {1}.";
   String^ m4 = "  (Press any key to continue...)";

    // 
   // Step 1: Get the current window dimensions. 
   //
   origWidth = Console::WindowWidth;
   origHeight = Console::WindowHeight; …
Run Code Online (Sandbox Code Playgroud)

c++ msdn windows-console

0
推荐指数
1
解决办法
1190
查看次数

基于分布的python随机抽样

在进入正题之前,我们先来看看python的默认采样方式,

>>> import random
>>> c=[1,2,3,100,101,102,103,104,105,106,109,110,111,112,113,114]
>>> random.sample(c,1)
[103]
>>> random.sample(c,1)
[3]
>>> random.sample(c,1)
[3]
>>> random.sample(c,1)
[2]
>>> random.sample(c,1)
[3]
>>> random.sample(c,1)
[2]
>>> random.sample(c,1)
[106]
>>> random.sample(c,1)
[3]
>>> random.sample(c,1)
[105]
>>> random.sample(c,1)
[110]
>>> random.sample(c,1)
[103]
>>> random.sample(c,1)
Run Code Online (Sandbox Code Playgroud)

源代码我们可以很容易地看到它实际上做了什么(以下是链接中代码的主要部分),

selected = set()
selected_add = selected.add
for i in xrange(k):
    j = _int(random() * n)
    while j in selected:
        j = _int(random() * n)
        selected_add(j)
        result[i] = population[j]
Run Code Online (Sandbox Code Playgroud)

这种抽样方法随机选择了一个指标。在这种情况下,有可能选择一个非常不可能的人口成员。比如说1上面的例子。

但让我们专注于一个更现实的场景。假设您有 16 个数字,表示来自0-15. …

python random statistics distribution

0
推荐指数
1
解决办法
4471
查看次数