> inf_indices <- which(is.infinite(df), arr.ind = TRUE) Error in is.infinite(df) : default method not implemented for type 'list'
时间: 2024-02-13 14:04:55 浏览: 33
这个错误信息的意思是说 is.infinite() 函数不支持列表类型的数据,因此无法对 df 列表进行操作。你可以尝试将 df 转换为一个矩阵或数据框,然后再试一下这个函数。例如,如果 df 是一个数据框,你可以使用 as.matrix() 函数将其转换为矩阵,然后再使用 is.infinite() 函数。具体操作可以参考下面的代码:
```
df_matrix <- as.matrix(df)
inf_indices <- which(is.infinite(df_matrix), arr.ind = TRUE)
```
这样就可以避免这个错误了。
相关问题
In file included from /home/yhdr/2-test-2023-06_v3/sent.h:24:0, from /home/yhdr/2-test-2023-06_v3/sent.cpp:1: /usr/include/c++/7/thread: In instantiation of ‘struct std::thread::_Invoker<std::tuple<void (*)(double*, double&, double&, double&, double&, double&), double**, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double> > >’: /usr/include/c++/7/thread:127:22: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(double*, double&, double&, double&, double&, double&); _Args = {double**, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>}]’ /home/yhdr/2-test-2023-06_v3/sent.cpp:18:153: required from here /usr/include/c++/7/thread:240:2: error: no matching function for call to ‘std::thread::_Invoker<std::tuple<void (*)(double*, double&, double&, double&, double&, double&), double**, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double> > >::_M_invoke(std::thread::_Invoker<std::tuple<void (*)(double*, double&, double&, double&, double&, double&), double**, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double> > >::_Indices)’ operator()() ^~~~~~~~ /usr/include/c++/7/thread:231:4: note: candidate: template<long unsigned int ..._Ind> decltype (std::__invoke((_S_declval<_Ind>)()...)) std::thread::_Invoker<_Tuple>::_M_invoke(std::_Index_tuple<_Ind ...>) [with long unsigned int ..._Ind = {_Ind ...}; _Tuple = std::tuple<void (*)(double*, double&, double&, double&, double&, double&), double**, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double>, std::reference_wrapper<double> >] _M_invoke(_Index_tuple<_Ind...>)
这个编译错误看起来是在创建一个std::thread对象时出现了问题。它指出无法匹配std::thread::_Invoker模板的_M_invoke函数的参数列表。这通常是因为您的函数参数与std::thread的参数不匹配,或者您的函数参数中有无法转换的类型。
请检查您的函数参数类型是否与std::thread需要的参数类型相匹配。如果您的函数需要接受其他参数类型,请尝试将它们转换为std::reference_wrapper或其他可转换的类型。您可能还需要检查您的函数参数数量是否正确。
如果您需要更多的帮助,请提供更多的代码和上下文,我可以更好地帮助您解决这个问题。
我是一个初学者,请你帮我解释以下这段代码的每个变量的含义和每句代码的语法:def top_k_top_p_filtering(logits, top_k=0, top_p=0.0, filter_value=-float('Inf')): assert logits.dim() == 1 # batch size 1 for now - could be updated for more but the code would be less clear top_k = min(top_k, logits.size(-1)) # Safety check if top_k > 0: # Remove all tokens with a probability less than the last token of the top-k # torch.topk()返回最后一维最大的top_k个元素,返回值为二维(values,indices) # ...表示其他维度由计算机自行推断 indices_to_remove = logits < torch.topk(logits, top_k)[0][..., -1, None] logits[indices_to_remove] = filter_value if top_p > 0.0: sorted_logits, sorted_indices = torch.sort(logits, descending=True) cumulative_probs = torch.cumsum(F.softmax(sorted_logits, dim=-1), dim=-1) # Remove tokens with cumulative probability above the threshold sorted_indices_to_remove = cumulative_probs > top_p # Shift the indices to the right to keep also the first token above the threshold sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone() sorted_indices_to_remove[..., 0] = 0 indices_to_remove = sorted_indices[sorted_indices_to_remove] logits[indices_to_remove] = filter_value return logits
这段代码的作用是根据给定的top_k和top_p值,过滤掉logits分数较低的预测结果,从而生成更准确的预测结果。下面是每个变量的含义和每句代码的语法:
1. `logits`:一个张量,表示对应词汇表中单词的logits分数。
2. `top_k`:一个整数,表示要保留的最高可能性预测的数量。
3. `top_p`:一个浮点数,表示要保留的累积概率质量。
4. `filter_value`:一个浮点数,用于过滤掉不想要的预测。默认值为负无穷大。
5. `assert`:断言语句,用于判断logits张量的维度是否为1,如果维度不为1,程序将会报错并停止运行。
6. `logits.dim()`:张量的维度数。
7. `top_k = min(top_k, logits.size(-1))`:将top_k值与logits张量的最后一维大小进行比较,保证top_k值不会大于张量的维度。
8. `if top_k > 0:`:如果指定了top_k值,则进行以下操作。
9. `indices_to_remove = logits < torch.topk(logits, top_k)[0][..., -1, None]`:返回logits张量中最后一维的最大值的top_k个元素,并将剩余元素的值设置为过滤值, 然后返回不需要的结果的索引。
10. `logits[indices_to_remove] = filter_value`:将logits张量中的索引为indices_to_remove的元素的值设置为过滤值。
11. `if top_p > 0.0:`:如果指定了top_p值,则进行以下操作。
12. `sorted_logits, sorted_indices = torch.sort(logits, descending=True)`:按照降序对logits张量进行排序,并返回排序后的结果和对应的索引。
13. `cumulative_probs = torch.cumsum(F.softmax(sorted_logits, dim=-1), dim=-1)`:计算softmax函数的累积概率值。
14. `sorted_indices_to_remove = cumulative_probs > top_p`:返回累积概率大于top_p的索引。
15. `sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone()`:将索引向右移一位,保留第一个索引。
16. `sorted_indices_to_remove[..., 0] = 0`:将第一个索引设置为0。
17. `indices_to_remove = sorted_indices[sorted_indices_to_remove]`:返回不需要的结果的索引。
18. `logits[indices_to_remove] = filter_value`:将logits张量中的索引为indices_to_remove的元素的值设置为过滤值。
19. `return logits`:返回过滤后的logits张量。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)