小编eya*_*klt的帖子

coursera作业python文件编译错误

我在 jupyter notebook 中有一个 coursera 作业,问题是在 jupyter 中它运行正常,但是当我提交失败并显示此错误时:无法编译学生的代码。无效语法(student_solution.py,第 23 行)

任务是:在本练习中,您将尝试构建一个神经网络,根据一个简单的公式预测房屋的价格。

因此,想象一下,如果房屋定价像每间卧室的房子价格为 50k + 50k 一样简单,那么 1 居室房屋的成本为 100k,2 居室房屋的成本为 150k 等等。

您将如何创建一个学习这种关系的神经网络,以便预测 7 间卧室的房子的成本接近 40 万等。

提示:如果您降低房价,您的网络可能会运行得更好。你不必给出 400 的答案......创建一些预测数字 4 的东西可能会更好,然后你的答案是“成百上千”等等。

我的回答是

import tensorflow as tf
import numpy as np
from tensorflow import keras
def house_model(y_new):
   xs = np.array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0], dtype=float)
   ys = np.array([100.0, 150.0, 200.0, 250.0, 300.0, 350.0, 450.0, 500.0, 550.0,600.0, 650.0,700.0], dtype=float)

   model = tf.keras.Sequential([keras.layers.Dense(units=1, input_shape=[1])])
   model.compile(optimizer='sgd',loss='mean_squared_error') …
Run Code Online (Sandbox Code Playgroud)

python tensorflow

4
推荐指数
1
解决办法
2910
查看次数

AttributeError:'spacy.tokens.span.Span'对象没有属性'merge'

我正在开发一个 nlp 项目并尝试遵循本教程https://medium.com/@ageitgey/natural-language-processing-is-fun-9a0bff37854e \n并在执行这部分时

\n
import spacy\n\n# Load the large English NLP model\nnlp = spacy.load(\'en_core_web_lg\')\n\n# Replace a token with "REDACTED" if it is a name\ndef replace_name_with_placeholder(token):\n   if token.ent_iob != 0 and token.ent_type_ == "PERSON":\n    return "[REDACTED] "\n  else:\n    return token.string\n\n # Loop through all the entities in a document and check if they are names\ndef scrub(text):\ndoc = nlp(text)\nfor ent in doc.ents:\n    ent.merge()\ntokens = map(replace_name_with_placeholder, doc)\nreturn "".join(tokens)\n\ns = """\nIn 1950, Alan Turing published his famous article "Computing Machinery and Intelligence". …
Run Code Online (Sandbox Code Playgroud)

python nlp spacy

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

标签 统计

python ×2

nlp ×1

spacy ×1

tensorflow ×1