Skip to content

Instantly share code, notes, and snippets.

View junichiro's full-sized avatar

Junichiro Tobe junichiro

  • Novasell
  • Tokyo, Japan
View GitHub Profile
@junichiro
junichiro / openai.rs
Created May 18, 2023 00:46
Rust で OpenAI API を呼ぶ例
use async_openai::{Client, types::{CreateCompletionRequestArgs}};
pub struct OpenAi {
client: Client,
model: String,
max_tokens: u16,
}
impl OpenAi {
pub fn new(model: String, max_tokens: u16) -> Self {
@junichiro
junichiro / openai_test.rs
Created May 18, 2023 00:48
Rust で OpenAI を呼ぶコードのテストコード
use app::openai::OpenAi;
#[tokio::test]
async fn test_openai() {
let input_text = "Hello, world!";
let client = OpenAi::new("text-davinci-003".to_string(), 400_u16);
let response_text = client.ask(input_text).await;
assert!(
response_text.contains(input_text),
"Expected '{}' to contain '{}'",
@junichiro
junichiro / file0.txt
Last active January 31, 2020 03:12
機械学習に必要な最急降下法の実装に必要な知識まとめ ref: https://qiita.com/junichiro/items/527b1f211ed814528ded
x := x - \frac{\partial}{\partial x}J(x, y) \\
y := y - \frac{\partial}{\partial y}J(x, y) \\
@junichiro
junichiro / file0.txt
Last active May 29, 2019 08:32
機械学習で精度が出ない時にやることまとめ ref: https://qiita.com/junichiro/items/7e2842c7afba2407c49b
err(h_\theta(x), y) = \left\{
\begin{array}{ll}
1 & (h_\theta(x) \geq 0.5, y = 0 \quad or \quad h_\theta(x) \lt 0.5, y = 1) \\
0 & (otherwise)
\end{array}
\right.
@junichiro
junichiro / file0.txt
Last active March 7, 2018 02:36
機械学習を1ヵ月で実践レベルにする #10 (正則化) ref: https://qiita.com/junichiro/items/8b1867201663c5af38a4
hx = X * theta;
cost = hx - y;
theta = [0; theta(2:end, :)];
J = ((cost' * cost) + lambda * (theta' * theta)) / (2 * m);
@junichiro
junichiro / file0.txt
Last active February 20, 2018 09:53
機械学習を1ヵ月で実践レベルにする #6 (Octave 実践編) ref: https://qiita.com/junichiro/items/7972b1b6ad3d087fbde0
a = [1, 2, 3]
b = [2, 3, 4]
ans = 0
for i, v in enumerate(a):
ans = ans + a[i] * b[i]
print(ans)
@junichiro
junichiro / file0.txt
Created February 19, 2018 08:43
会社で少し盛り上がった Project Euler をやってみる 018 ref: https://qiita.com/junichiro/items/176ccccf09d66c59ba17
以下の三角形の頂点から下まで移動するとき, その数値の和の最大値は23になる.
3
7 4
2 4 6
8 5 9 3
この例では 3 + 7 + 4 + 9 = 23.
以下の三角形を頂点から下まで移動するとき, その最大の和を求めよ.
@junichiro
junichiro / file0.txt
Created February 14, 2018 03:57
会社で少し盛り上がった Project Euler をやってみる 017 ref: https://qiita.com/junichiro/items/ee3a312fca2510d82d94
import sys
class Problem17:
COUNT = {
0: '',
1: 'one',
2: 'two',
3: 'three',
@junichiro
junichiro / file0.txt
Created February 13, 2018 04:21
会社で少し盛り上がった Project Euler をやってみる 016 ref: https://qiita.com/junichiro/items/2e17dd0220a3281b2dfd
import sys
class Problem16:
def main(self, n):
return sum(int(i) for i in str(2 ** n))
if __name__ == '__main__':
@junichiro
junichiro / file0.txt
Last active February 9, 2018 00:36
会社で少し盛り上がった Project Euler をやってみる 015 ref: https://qiita.com/junichiro/items/76c0bf6ab32cb5121857
import sys
class Problem15:
def main(self, n):
tensor = [list(range(n + 1)) for i in range(n + 1)]
for i in range(n + 1):
for j in range(n + 1):
if i > 0 and j > 0: