小编And*_*rey的帖子

语言建模中的 Transformer 是否需要位置编码?

我正在开发一个语言模型,例如https://pytorch.org/tutorials/beginner/transformer_tutorial.html的语言模型。

\n\n

我不清楚 - 这里是否需要位置编码?\n据我了解 - 对于语言翻译任务来说这是必要的,因为解码器应该能够在编码器的序列中定位先前输出的单词。\n但是在没有解码器的语言建模中是否有必要?

\n\n

编码器输出中的单词是否可能被打乱?

\n\n

编辑:

\n\n

原论文中没有任何解释。我没有在教程中找到解释(就像这里https://kazemnejad.com/blog/transformer_architecture_positional_encoding/)。

\n\n

我不明白这一点:

\n\n

“由于句子中的每个单词同时流经 Transformer\xe2\x80\x99s 编码器/解码器堆栈,因此模型本身\xe2\x80\x99t 对每个单词没有任何位置/顺序感。”

\n\n

从我的角度来看,Transformer 编码器具有有关顺序的信息,因为它的输入是有序序列(类似于 RNN)。

\n\n

我尝试从模型中删除位置编码。它可以工作,但性能较差。

\n\n

将这种位置编码添加到 RNN 中有用吗?它可以提高其性能吗?

\n

transformer-model language-model

6
推荐指数
1
解决办法
4667
查看次数

将图像保存到 Cloud firestore

将图像上传到 firebase 存储后,如何将图像保存到 firebase firestore?

我应该有带有标题和图像的帖子,但我不知道如何做图像部分。

我的代码如下所示......

import Foundation
import FirebaseFirestore


protocol DocumentSerializable {
    init?(dictionary:[String:Any])
}


struct Post {
    var name: String
    var content: String
    var downloadURL: String
    
    var dictionary: [String:Any] {
        
        return [
            "name": name,
            "content": content,
            "imageDownloadURL": downloadURL
        ]
    }
    
}

extension Post: DocumentSerializable {
    init?(dictionary: [String : Any]) {
        guard let name = dictionary["name"] as? String,
        let content = dictionary["content"] as? String,
            let downloadURL = dictionary["imageDownloadURL"] as? String else {return nil}
        
        self.init(name: name, content: content, downloadURL: downloadURL) …
Run Code Online (Sandbox Code Playgroud)

firebase swift google-cloud-firestore

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

在 EMR 笔记本上安装 python 包时出现致命错误:Python.h:没有这样的文件或目录

我需要ahocorasick在 EMR 笔记本上安装软件包。

但是当我打电话时:

sc.install_pypi_package("pyahocorasick")
Run Code Online (Sandbox Code Playgroud)

我收到错误:

common.h:15:10: fatal error: Python.h: No such file or directory

   #include <Python.h>

            ^~~~~~~~~~

  compilation terminated.

  error: command 'gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)

pandas安装没有任何问题。

作为引导操作安装时,我遇到类似的错误。

如果我打电话:

%pip install pyahocorasick
Run Code Online (Sandbox Code Playgroud)

它安装得很好,但我无法导入它。

我尝试了这种方法:致命错误:Python.h:没有这样的文件或目录,python-Levenshtein install

但我找不到任何sudo从笔记本运行的方法。

编辑:

我尝试gcc在 bootstrap 阶段安装以下.sh文件:

sudo yum -y install gcc
sudo yum -y install python3-devel
sudo pip3 install pyahocorasick --user
Run Code Online (Sandbox Code Playgroud)

这没有帮助 - 我在通话时仍然收到错误import ahocorasick

python pip amazon-emr pyspark

5
推荐指数
0
解决办法
999
查看次数

如何检查 TPU 在 Google Colab 中是否可用?

我正在尝试根据 TPU 的可用性选择分配策略。

我的代码如下:

import tensorflow as tf
if tf.config.list_physical_devices('tpu'):
  resolver = tf.distribute.cluster_resolver.TPUClusterResolver()
  tf.config.experimental_connect_to_cluster(resolver)
  tf.tpu.experimental.initialize_tpu_system(resolver)
  print("All devices: ", tf.config.list_logical_devices('TPU'))
  strategy = tf.distribute.experimental.TPUStrategy(resolver)
else:  # use default strategy
  strategy = tf.distribute.get_strategy() 
Run Code Online (Sandbox Code Playgroud)

但这不起作用。

如何识别TPU?

tensorflow google-colaboratory tpu tensorflow2.0

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

如何获取 pandas 表中时间间隔内具有 DatetimeIndex 的行?

我正在使用这个方法:

df = pd.DataFrame({'date': [datetime(2021, 11, 1, 13, 30), datetime(2021, 11, 2, 13, 31), datetime(2021, 11, 3, 13, 32), datetime(2021, 11, 1, 13, 33)],
                    'value': [1, 2, 3, 5]})
df = df.set_index('date')
df = df.loc[
  (df.index.time >= datetime.strptime("13:30", '%H:%M').time()) & \
  (df.index.time < datetime.strptime("13:32", '%H:%M').time())]
Run Code Online (Sandbox Code Playgroud)

还有更好的办法吗?

我尝试使用between()

df = df.loc[
  df.index.time.between(
    datetime.strptime("13:30", '%H:%M').time(),
    datetime.strptime("13:32", '%H:%M').time())]
Run Code Online (Sandbox Code Playgroud)

它会产生一个错误:

'numpy.ndarray' object has no attribute 'between'
Run Code Online (Sandbox Code Playgroud)

而且我没有找到合适的numpy功能。

python pandas

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

如何在 C++ 中分配二维初始值设定项列表?

我从向量继承了我的类,我希望能够像向量一样将列表分配给我的类。

我的代码如下:

#include <vector>
using namespace std;

template<typename T>
class Matrix
    : public vector<vector<T>>
{
public:
    Matrix( vector<vector<T>> && m )
        : vector<vector<T>>( m )
    {}

    // Tried this approach, but it doesn't work
    // Matrix(std::initializer_list<std::initializer_list<T>> l){
    // }
}

int main()
{
  Matrix<int> m({{0, 1}, {2, 3}}); // it works
  // Matrix<int> m = {{0, 1}, {2, 3}}; // error: no instance of constructor "Matrix<T>::Matrix [with T=int]" matches the argument list -- argument types are: ({...}, {...})
}
Run Code Online (Sandbox Code Playgroud)

c++ vector initializer-list

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