pub struct TextSummarizer { /* private fields */ }
Expand description
Text summarizer using quantum language models
Implementations§
Source§impl TextSummarizer
impl TextSummarizer
Sourcepub fn new(num_qubits: usize) -> Result<Self>
pub fn new(num_qubits: usize) -> Result<Self>
Creates a new text summarizer
Examples found in repository?
examples/quantum_nlp.rs (line 143)
133fn run_text_summarization() -> Result<()> {
134 println!("\nText Summarization Example");
135 println!("-------------------------");
136
137 // Create text summarizer
138 let num_qubits = 8;
139 println!(
140 "Creating quantum text summarizer with {} qubits",
141 num_qubits
142 );
143 let summarizer = quantrs2_ml::nlp::TextSummarizer::new(num_qubits)?;
144
145 // Text to summarize
146 let long_text = "Quantum computing is a rapidly-emerging technology that harnesses the laws of quantum mechanics to solve problems too complex for classical computers. While traditional computers use bits as the smallest unit of data, quantum computers use quantum bits or qubits. Qubits can represent numerous possible combinations of 1 and 0 at the same time through a property called superposition. This allows quantum computers to consider and manipulate many combinations of information simultaneously, making them well suited to specific types of complex calculations. Another key property of quantum computing is entanglement, which allows qubits that are separated by great distances to still be connected. Changing the state of one entangled qubit will instantaneously change the state of its partner regardless of how far apart they are. Quantum computers excel at solving certain types of problems, such as factoring very large numbers, searching unsorted databases, and simulating quantum systems like molecules for drug development. However, they are not expected to replace classical computers for most everyday tasks. Major technology companies including IBM, Google, Microsoft, Amazon, and several startups are racing to build practical quantum computers. In 2019, Google claimed to have achieved quantum supremacy, performing a calculation that would be practically impossible for a classical computer. While current quantum computers are still limited by high error rates and the need for extreme cooling, they represent one of the most promising frontier technologies of the 21st century.";
147
148 println!("\nOriginal text ({} characters):", long_text.len());
149 println!("{}\n", long_text);
150
151 // Generate summary
152 println!("Generating quantum summary...");
153 let start = Instant::now();
154 let summary = summarizer.summarize(long_text)?;
155 println!("Summarization completed in {:.2?}", start.elapsed());
156
157 println!("\nSummary ({} characters):", summary.len());
158 println!("{}", summary);
159
160 // Calculate compression ratio
161 let compression = 100.0 * (1.0 - (summary.len() as f64) / (long_text.len() as f64));
162 println!("\nCompression ratio: {:.1}%", compression);
163
164 Ok(())
165}
Sourcepub fn with_max_length(self, max_length: usize) -> Self
pub fn with_max_length(self, max_length: usize) -> Self
Sets the maximum summary length
Sourcepub fn summarize(&self, text: &str) -> Result<String>
pub fn summarize(&self, text: &str) -> Result<String>
Summarizes text
Examples found in repository?
examples/quantum_nlp.rs (line 154)
133fn run_text_summarization() -> Result<()> {
134 println!("\nText Summarization Example");
135 println!("-------------------------");
136
137 // Create text summarizer
138 let num_qubits = 8;
139 println!(
140 "Creating quantum text summarizer with {} qubits",
141 num_qubits
142 );
143 let summarizer = quantrs2_ml::nlp::TextSummarizer::new(num_qubits)?;
144
145 // Text to summarize
146 let long_text = "Quantum computing is a rapidly-emerging technology that harnesses the laws of quantum mechanics to solve problems too complex for classical computers. While traditional computers use bits as the smallest unit of data, quantum computers use quantum bits or qubits. Qubits can represent numerous possible combinations of 1 and 0 at the same time through a property called superposition. This allows quantum computers to consider and manipulate many combinations of information simultaneously, making them well suited to specific types of complex calculations. Another key property of quantum computing is entanglement, which allows qubits that are separated by great distances to still be connected. Changing the state of one entangled qubit will instantaneously change the state of its partner regardless of how far apart they are. Quantum computers excel at solving certain types of problems, such as factoring very large numbers, searching unsorted databases, and simulating quantum systems like molecules for drug development. However, they are not expected to replace classical computers for most everyday tasks. Major technology companies including IBM, Google, Microsoft, Amazon, and several startups are racing to build practical quantum computers. In 2019, Google claimed to have achieved quantum supremacy, performing a calculation that would be practically impossible for a classical computer. While current quantum computers are still limited by high error rates and the need for extreme cooling, they represent one of the most promising frontier technologies of the 21st century.";
147
148 println!("\nOriginal text ({} characters):", long_text.len());
149 println!("{}\n", long_text);
150
151 // Generate summary
152 println!("Generating quantum summary...");
153 let start = Instant::now();
154 let summary = summarizer.summarize(long_text)?;
155 println!("Summarization completed in {:.2?}", start.elapsed());
156
157 println!("\nSummary ({} characters):", summary.len());
158 println!("{}", summary);
159
160 // Calculate compression ratio
161 let compression = 100.0 * (1.0 - (summary.len() as f64) / (long_text.len() as f64));
162 println!("\nCompression ratio: {:.1}%", compression);
163
164 Ok(())
165}
Trait Implementations§
Source§impl Clone for TextSummarizer
impl Clone for TextSummarizer
Source§fn clone(&self) -> TextSummarizer
fn clone(&self) -> TextSummarizer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for TextSummarizer
impl RefUnwindSafe for TextSummarizer
impl Send for TextSummarizer
impl Sync for TextSummarizer
impl Unpin for TextSummarizer
impl UnwindSafe for TextSummarizer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.