poem_loop

This commit is contained in:
mehbark 2024-11-14 00:31:51 -05:00
parent cb549c5988
commit 5058285c72
5 changed files with 180 additions and 49 deletions

46
Cargo.lock generated
View file

@ -26,6 +26,31 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "crossbeam-deque"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d"
dependencies = [
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80"
[[package]] [[package]]
name = "crypto-common" name = "crypto-common"
version = "0.1.6" version = "0.1.6"
@ -82,9 +107,30 @@ name = "pearls"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"itertools", "itertools",
"rayon",
"sha2", "sha2",
] ]
[[package]]
name = "rayon"
version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2"
dependencies = [
"crossbeam-deque",
"crossbeam-utils",
]
[[package]] [[package]]
name = "sha2" name = "sha2"
version = "0.10.8" version = "0.10.8"

View file

@ -5,4 +5,5 @@ edition = "2021"
[dependencies] [dependencies]
itertools = "0.13.0" itertools = "0.13.0"
rayon = "1.10.0"
sha2 = "0.10.8" sha2 = "0.10.8"

19
extract_poems.rb Normal file
View file

@ -0,0 +1,19 @@
# frozen_string_literal: true
MIN_8S = 0
def max_8s(str)
(str.scan(/8+/).max || '').length
end
$stdin.read.split('poem: ')
.map(&:strip)
.reject(&:empty?)
.to_set
.map { [_1, `printf "#{_1}" | openssl sha256`.strip] }
.filter { |(_, hash)| max_8s(hash) >= MIN_8S }
.sort_by { |(_, hash)| max_8s hash }
.each do |(amulet, hash)|
puts amulet
puts "#{max_8s hash} #{hash}#{amulet.length > 64 ? ' too long!' : ''}"
end

52
poem_loop.rb Normal file
View file

@ -0,0 +1,52 @@
# frozen_string_literal: true
LLAMA_PATH = "#{Dir.home}/Downloads/Meta-Llama-3-8B-Instruct.Q5_K_M.llamafile"
PROMPT = <<~END_OF_PROMPT
poem: If you can't write poems,
write me
poem: IN THE SPRING MY LUNGS
STILL SOMEHOW EXPAND.
poem: A MAN ONCE MAILED ME
A PIECE OF HIS HEART
poem: THIS AMULET
AT ANY PRICE
FELT LIKE THE TRUTH
poem: this amulet is a simple token which proves my love's truth
poem: sphinx of black quartz, judge my vow
poem: DON'T WORRY.
poem: in the early hours of the new year
i lie on my back
waiting.
poem: All my life I had this
image of what a poet
should be
poem: Winter evening, a leaf, a blue sky above.
poem: Lethargically good.
poem:
END_OF_PROMPT
.strip
def doit!
r, w = IO.pipe
spawn("#{LLAMA_PATH} --no-display-prompt --gpu APPLE -n 128 -p \"#{PROMPT}\"", out: w, err: '/dev/null')
spawn('ruby extract_poems.rb', in: r)
Process.wait
# just in case
r.close
w.close
end
doit!
doit!

View file

@ -1,7 +1,11 @@
use std::process::exit;
use itertools::Itertools; use itertools::Itertools;
use rayon::prelude::*;
use sha2::{Digest, Sha256}; use sha2::{Digest, Sha256};
// we could be smart with prefixes // we could be smart with prefixes
#[allow(clippy::too_many_lines)]
fn main() { fn main() {
let choices = [ let choices = [
vec![ vec![
@ -40,47 +44,47 @@ fn main() {
vec!["this sentence", "this message", "this piece of digitext"], vec!["this sentence", "this message", "this piece of digitext"],
vec![" has "], vec![" has "],
vec![ vec![
"seven", "ten",
"7", "10",
"7 (seven)", "10 (ten)",
"seven (7)", "ten (10)",
"7!", "10!",
"7(!)", "10(!)",
"seven!", "ten!",
"seven(!)", "ten(!)",
"7!!", "10!!",
"7(!!)", "10(!!)",
"seven!!", "ten!!",
"seven(!!)", "ten(!!)",
"7!!!", "10!!!",
"7(!!!)", "10(!!!)",
"seven!!!", "ten!!!",
"seven(!!!)", "ten(!!!)",
"7!!!!!!!", "10!!!!!!!!!!",
"7(!!!!!!!)", "10(!!!!!!!!!!)",
"seven!!!!!!!", "ten!!!!!!!!!!",
"seven(!!!!!!!)", "ten(!!!!!!!!!!)",
], ],
vec![" "], vec![" "],
vec![ vec![
"7s", "0s",
"sevens", "zeroes",
"7s!", "0s!",
"7s(!)", "0s(!)",
"sevens!", "zeroes!",
"sevens(!)", "zeroes(!)",
"7s!!", "0s!!",
"7s(!!)", "0s(!!)",
"sevens!!", "zeroes!!",
"sevens(!!)", "zeroes(!!)",
"7s!!!", "0s!!!",
"7s(!!!)", "0s(!!!)",
"sevens!!!", "zeroes!!!",
"sevens(!!!)", "zeroes(!!!)",
"7s!!!!!!!", "0s!!!!!!!!!!",
"7s(!!!!!!!)", "0s(!!!!!!!!!!)",
"sevens!!!!!!!", "zeroes!!!!!!!!!!",
"sevens(!!!!!!!)", "zeroes(!!!!!!!!!!)",
], ],
vec![" "], vec![" "],
vec![ vec![
@ -101,16 +105,25 @@ fn main() {
vec![" "], vec![" "],
vec!["somewhat ", "pretty ", "quite ", "very ", "decently ", ""], vec!["somewhat ", "pretty ", "quite ", "very ", "decently ", ""],
vec!["fun", "nice", "sweet", "pleasant", "cool", "interesting"], vec!["fun", "nice", "sweet", "pleasant", "cool", "interesting"],
vec![" "],
vec![
":)", ":D", ":))", ":)))", "XD", ":B", ">:)", ">:D", ">XD", ">:B", "B)", "BD", ">B)",
">BD", "(:", "((:", "(((:", "(:<",
],
]; ];
for selection in choices.into_iter().multi_cartesian_product() { choices
.into_iter()
.multi_cartesian_product()
.par_bridge()
.for_each(|selection| {
let mut hasher = Sha256::new(); let mut hasher = Sha256::new();
for choice in &selection { for choice in &selection {
hasher.update(choice); hasher.update(choice);
} }
let digest = hasher.finalize(); let digest = hasher.finalize();
if format!("{digest:x}").contains("7777777") { if format!("{digest:x}").contains("0000000000") {
println!("{}", selection.join("")); println!("{}\n{digest:x}", selection.join(""));
println!("{digest:x}"); exit(0);
}
} }
});
} }