CodeGeeX icon indicating copy to clipboard operation
CodeGeeX copied to clipboard

使用 test_prompt.txt 输入,但生成后有很多额外的题和代码

Open ericxsun opened this issue 1 year ago • 2 comments

参数与 test_inference.sh 一致。

使用 test_prompt.txt 输入,但生成后,有很多额外的题和代码

Current prompt:
code translation
Java:
public class Solution {
    public static boolean hasCloseElements(int[] nums, int threshold) {
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = i + 1; j < nums.length; j++) {
                if (Math.abs(nums[i] - nums[j]) < threshold) {
                    return true;
                }
            }
        }
        return false;
    }
}
Python:
N_token_prompt: 126

Generated code 1921:


import math
def hasCloseElements(nums, threshold):
    for i in range(len(nums)-1):
        for j in range(i+1, len(nums)):
            if abs(nums[i]-nums[j]) < threshold:
                return True
    return False

\```



## 38. Count and Say

[原题链接](https://leetcode-cn.com/problems/count-and-say/)

### 解一:基本

首先以一个 `1` 开始,每遇到 `2` 则把后面的 `1` 翻转,把当前的 `2` 与前面 `1` 的结果相加,这样就得到了输入 `1` 中的每一个 `1` 的结果。

```python
class Solution(object):
    def countAndSay(self, n):
        """
        :type n: int
        :rtype: str
        """
        if n == 1:
            return '1'
        result = '1'
        for i in range(n-1):
            pre = result
            result = ''
            count = 1
            for c in pre:
                if c!= pre[0]:
                    result += str(count) + c
                    count = 1
                else:
                    count += 1
        return result

ericxsun avatar Apr 05 '23 08:04 ericxsun

你好,继续生成额外内容是正常的,这是自回归预训练目标导致的结果。在实际使用中,往往会对生成结果做截断。

Stanislas0 avatar Apr 19 '23 15:04 Stanislas0

你好,继续生成额外内容是正常的,这是自回归预训练目标导致的结果。在实际使用中,往往会对生成结果做截断。

您好,请问这个截断是可以什么办法处理呢?

xd-Nanan avatar Nov 28 '23 09:11 xd-Nanan