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 134)
127fn run_text_summarization() -> Result<()> {
128 println!("\nText Summarization Example");
129 println!("-------------------------");
130
131 // Create text summarizer
132 let num_qubits = 8;
133 println!("Creating quantum text summarizer with {num_qubits} qubits");
134 let summarizer = quantrs2_ml::nlp::TextSummarizer::new(num_qubits)?;
135
136 // Text to summarize
137 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.";
138
139 println!("\nOriginal text ({} characters):", long_text.len());
140 println!("{long_text}\n");
141
142 // Generate summary
143 println!("Generating quantum summary...");
144 let start = Instant::now();
145 let summary = summarizer.summarize(long_text)?;
146 println!("Summarization completed in {:.2?}", start.elapsed());
147
148 println!("\nSummary ({} characters):", summary.len());
149 println!("{summary}");
150
151 // Calculate compression ratio
152 let compression = 100.0 * (1.0 - (summary.len() as f64) / (long_text.len() as f64));
153 println!("\nCompression ratio: {compression:.1}%");
154
155 Ok(())
156}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 145)
127fn run_text_summarization() -> Result<()> {
128 println!("\nText Summarization Example");
129 println!("-------------------------");
130
131 // Create text summarizer
132 let num_qubits = 8;
133 println!("Creating quantum text summarizer with {num_qubits} qubits");
134 let summarizer = quantrs2_ml::nlp::TextSummarizer::new(num_qubits)?;
135
136 // Text to summarize
137 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.";
138
139 println!("\nOriginal text ({} characters):", long_text.len());
140 println!("{long_text}\n");
141
142 // Generate summary
143 println!("Generating quantum summary...");
144 let start = Instant::now();
145 let summary = summarizer.summarize(long_text)?;
146 println!("Summarization completed in {:.2?}", start.elapsed());
147
148 println!("\nSummary ({} characters):", summary.len());
149 println!("{summary}");
150
151 // Calculate compression ratio
152 let compression = 100.0 * (1.0 - (summary.len() as f64) / (long_text.len() as f64));
153 println!("\nCompression ratio: {compression:.1}%");
154
155 Ok(())
156}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.