我无法在NLTK中导入NER Stanford Tagger.这就是我所做的:
从这里下载了java代码,
并添加了一个环境变量STANFORD_MODELS,其中包含存储java代码的文件夹的路径.
根据NLTK网站上提供的信息,这应该足够了.它说:
"Tagger模型需要从http://nlp.stanford.edu/software和STANFORD_MODELS环境变量集(以冒号分隔的路径列表)下载."
请问有人帮助我吗?
编辑:下载的文件夹位于/ Users/-----------/Documents/JavaJuno/stanford-ner-2015-04-20并包含以下文件:
LICENSE.txt lib ner.sh stanford-ner-3.5.2-javadoc.jar
NERDemo.java ner-gui.bat sample-conll-file.txt stanford-ner-3.5.2-sources.jar
README.txt ner-gui.command sample-w-time.txt stanford-ner-3.5.2.jar
build.xml ner-gui.sh sample.ner.txt stanford-ner.jar
classifiers ner.bat sample.txt
Run Code Online (Sandbox Code Playgroud)
然后我添加了一个环境变量STANFORD_MODELS:
os.environ["STANFORD_MODELS"] = "/Users/-----------/Documents/JavaJuno/stanford-ner-2015-04-20"
Run Code Online (Sandbox Code Playgroud)
从nltk.tag导入调用StanfordNERTagger会产生错误:
ImportError Traceback (most recent call last)
<ipython-input-356-f4287e573edc> in <module>()
----> 1 from nltk.tag import StanfordNERTagger
ImportError: cannot import name StanfordNERTagger
Run Code Online (Sandbox Code Playgroud)
如果这可能是相关的,这就是我的nltk.tag文件夹中的内容:
__init__.py api.pyc crf.py hmm.pyc senna.py sequential.pyc stanford.py tnt.pyc
__init__.pyc brill.py crf.pyc hunpos.py senna.pyc simplify.py stanford.pyc util.py
api.py brill.pyc hmm.py …Run Code Online (Sandbox Code Playgroud) 鉴于以下课程:
class BasicRNNCell(RNNCell):
"""The most basic RNN cell."""
def __init__(self, num_units, input_size=None):
self._num_units = num_units
self._input_size = num_units if input_size is None else input_size
@property
def input_size(self):
return self._input_size
@property
def output_size(self):
return self._num_units
@property
def state_size(self):
return self._num_units
def __call__(self, inputs, state, scope=None):
"""Most basic RNN: output = new_state = tanh(W * input + U * state + B)."""
with vs.variable_scope(scope or type(self).__name__): # "BasicRNNCell"
output = tanh(linear([inputs, state], self._num_units, True))
return output, output
Run Code Online (Sandbox Code Playgroud)
我不明白他们为什么在这种情况下使用属性函数.使用input_size函数的属性装饰器允许在一个对象上调用input_size,让它称之为该类的单元格,但为什么它们只是简单地调用cell._input_size?谁能告诉我为什么这有用呢?
我第一次尝试在C++中使用正则表达式,我对转义序列有点困惑.我只是想在一个字符串的开头匹配一个点.为此,我使用了表达式:"^ \\\.",它有效,但我的编译器(g ++)生成一个警告:
warning: unknown escape sequence '\.'
regex self_regex("^\\\.");
^~
Run Code Online (Sandbox Code Playgroud)
如果我使用例如"^ \\.",它不会产生警告,但正则表达式与我打算做的不符.
我也不明白为什么我必须使用三个反斜杠,不应该两个就足够了,在"\"中.第一个反斜杠逃脱第二个,所以我实际上搜索.,但它不起作用.有人可以帮我澄清一下吗?
码:
#include <iostream>
#include <dirent.h>
#include <regex>
using namespace std;
int main(void){
DIR *dir;
string path = "/Users/-----------/Documents/Bibliothek/MachineLearning/DeepLearning/ConvolutionalNeuralNetworks/CS231n 2016/Assignments/assignment3/assignment3/cs231n";
regex self_regex("^\\\.+");
struct dirent *ent;
dir = opendir(path.c_str());
if ((dir = opendir(path.c_str())) != NULL){
while ((ent = readdir(dir)) != NULL){
if (regex_search(string(ent->d_name),self_regex)){
cout << "matches regex" << ent->d_name << endl;
}
else{
cout << "does not match regex " << ent->d_name << endl;
}
}
closedir(dir);
} …Run Code Online (Sandbox Code Playgroud) 我遇到了以下问题,我有四个嵌入矩阵,想获得我的损失函数相对于这些矩阵的梯度。
当我运行会话以返回梯度值时,其中两个返回的对象是 tensorflow.python.framework.ops.IndexedSlicesValue 类型,另外两个是 numpy 数组。现在对于 numpy 数组,它们的形状对应于它们对应的嵌入矩阵的形状,但是我在使用 IndexedSlicesValue 对象时遇到了问题。
如果我在其中一个对象上调用 .values,我会得到一个形状与渐变不匹配的数组,嵌入矩阵的形状是 [22,30],但是在 IndexedSlicesValue 对象上调用 .values 会得到一个数组形状为 [4200,30] (我输入张量的形状尺寸为 [30,20,7],这些尺寸的乘积等于 4200,不确定这是否相关)。IndexedSlicesValue 对象有一个名为dense_shape 的属性,它是一个数组,保存梯度应该具有的维度,即array([22,30]) 是.dense_shape 返回的值。
我不太了解这里的文档:https : //www.tensorflow.org/versions/r0.7/api_docs/python/state_ops.html#IndexedSlices
它说:
IndexedSlices 通常用于表示形状为 [LARGE0, D1, .. , DN] 的较大张量密集的子集,其中 LARGE0 >> D0。索引中的值是从较大张量中提取的切片的第一维中的索引。
那么这个形状数组 (4200,30) 是从一个数组中提取的,该数组对应于一个更大的密集张量?
这个 IndexedSlicesValue 对象中的梯度到底是什么,为什么 tensorflow 会自动将这种类型用于 tf.gradients() 返回的某些梯度?
这是我的代码:
input_tensor = tf.placeholder(tf.int32, shape = [None, memory_size, max_sent_length], name = 'Input')
q_tensor = tf.placeholder(tf.int32, shape = [None,max_sent_length], name = 'Question')
a_tensor = tf.placeholder(tf.float32, shape = [None,V+1], name = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 psycopg2 执行“插入表”命令。我在函数中创建命令字符串,该函数返回以下形式的字符串:
create table %s ( %s %s , %s %s , %s %s , %s %s , %s %s , %s %s , %s %s , %s %s , %s %s , %s %s , %s %s , primary key %s );
Run Code Online (Sandbox Code Playgroud)
该函数还返回一个字符串变量元组,我想用它来填充格式字符串:
('games', 'score_loser', 'integer', 'playoffs', 'boolean', 'record_loser', 'integer[]', 'broadcast', 'varchar(20)', 'date', 'date', 'id', 'varchar (30)', 'home_team', 'varchar (50)', 'record_winner', 'integer[]', 'winner', 'varchar (50)', 'loser', 'varchar (50)', 'score_winner', 'integer', 'id')
Run Code Online (Sandbox Code Playgroud)
但是当我尝试执行该命令时,我遇到了一个问题,即元组中的变量被放入单引号中,这会导致 psycopg2 中出现语法错误:
psycopg2.ProgrammingError: syntax error at …Run Code Online (Sandbox Code Playgroud) 我在 Rust 中有一个 Graph 数据结构:
type NodeIndex = usize;
struct Graph {
nodes: Vec<NodeIndex>,
edges: Vec<(NodeIndex, NodeIndex)>,
}
Run Code Online (Sandbox Code Playgroud)
我想遍历函数内的所有节点并调用一个函数,该函数使用每个节点作为元素来改变图形,例如:
impl Graph {
fn mutate_fn(&mut self) {
for node in self.nodes {
self.mutate_using_node(node);
}
}
fn mutate_using_node(&mut self, node: NodeIndex) {
// mutate self here
}
}
Run Code Online (Sandbox Code Playgroud)
这是行不通的,因为我会有不止一个可变引用。我也不能通过 &self,因为那样我就会有一个可变引用和一个不可变引用。这在 Rust 中是如何处理的?
我正在使用 tensorflow 1.0.0 并且我想访问 tensorflow.layers 模块。该模块似乎存在:
In [12]: dir(tensorflow.layers)
Out[12]:
['__builtins__',
'__doc__',
'__file__',
'__name__',
'__package__',
'_allowed_symbols',
'average_pooling1d',
'average_pooling2d',
'average_pooling3d',
'batch_normalization',
'conv1d',
'conv2d',
'conv2d_transpose',
'conv3d',
'dense',
'dropout',
'max_pooling1d',
'max_pooling2d',
'max_pooling3d',
'separable_conv2d']
Run Code Online (Sandbox Code Playgroud)
但是当我尝试导入例如密集函数时:
In [13]: from tensorflow.layers import dense
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-13-e5b2c910300d> in <module>()
----> 1 from tensorflow.layers import dense
ImportError: No module named layers
Run Code Online (Sandbox Code Playgroud)
为什么python不能访问模块?
我有一个函数需要返回两个不同类型的向量组.我可以使用由两个矩阵组成的列表来做到这一点,其中我想要返回的向量对应于矩阵中的列,但由于向量都具有不同的长度,我想将这些向量本身保存在列表中,所以我有一个由两个列表组成的列表.
我想现在将向量添加到子列表中,但不知道要使用哪些索引.
例如,如果我想将向量x添加到列表中的第一个子列表(称之为l),我该怎么做?
l[[1]] <- x
Run Code Online (Sandbox Code Playgroud)
只会替换第一个子列表中的第一个向量,但是如何使用索引访问子列表中的第二个元素?
假设l是整数列表而win是整数,则以下代码生成lpadded列表:
lpadded = win // 2 * [-1] + l + win // 2 * [-1]
Run Code Online (Sandbox Code Playgroud)
在lpadded -1中填充到列表的开头和结尾,但我完全不知道该代码如何生成此列表.这里[-1]对整数有什么作用?我以前从未见过这种python语法.
我想根据条件声明一个特定大小的数组,但是Eclipse给了我一个错误.这是我的条件:
Run Code Online (Sandbox Code Playgroud)if ( (a.length == b.length) && (a[maxlength - 1] + b[maxlength - 1] >= 10)) int[] c = new int[maxlength + 1]; else int[] c = new int[maxlength];
我在两个数组声明的行上得到以下错误:
为什么这不起作用?是否有其他方法可以实现同一目标?
我是套接字编程的新手,我只是在尝试一些东西。我正在尝试做的是让一个客户端读取一个文本文件,将该文件中的行保存在ArrayList中,然后将这些行发送到服务器。这是我的代码。连接已成功建立,但是当服务器尝试从其BufferedReader读取时,它什么也没得到:
服务器:
import java.io.*;
import java.net.*;
public class Server extends Thread{
ServerSocket sock = null;
Socket client_sock = null;
PrintWriter out = null;
BufferedReader in = null;
Server(int port){
try{
sock = new ServerSocket(port);
}catch(IOException e){
System.out.println("Couldn't create server socket");
e.printStackTrace();
}
}
public void run(){
while (true){
try{
client_sock = sock.accept();
System.out.println("Successfully connected to client" + client_sock);
System.out.println(client_sock.getOutputStream());
System.out.println(client_sock.getInputStream());
out = new PrintWriter(client_sock.getOutputStream(),true);
//System.out.println(out);
in = new BufferedReader(new InputStreamReader(client_sock.getInputStream()));
//System.out.println(in);
System.out.println("Trying to read line sent from client:");
String l; …Run Code Online (Sandbox Code Playgroud)